-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
9-suhyun113 #33
9-suhyun113 #33
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
κ°μκΈ° λ¬Έμ 3κ°λ₯Ό λμ Έλ²λ¦¬λ γ·γ·
μ΅λ¨ κ²½λ‘ κ΅¬νκΈ°λ λ€μ΅μ€νΈλΌ λ§κ³ λ "νλ‘μ΄λ-μμ "λ κ² μμ£ ? μ΄λ²μ κ·Έκ²λ μΈλΌμ΄μΈλΌμ΄~
|
||
for _ in range(M): | ||
x, y, cost = map(int, input().split()) # x -> y λμλ‘ κ°λ λ° νμν λΉμ© cost | ||
graph[x].append([y, cost]) # κ·Έλνμ μμ§ μΆκ° |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ¬μν νμΈλ°, graphμ μ 보λ "λΆλ³"μ΄λ―λ‘ (μΈμ λ Έλ, λΉμ©) μ 보λ₯Ό listλ‘ λ£μ§ λ§κ³ tupleλ‘ λ£μΌλ©΄ λ©λͺ¨λ¦¬μ μλ μΈ‘λ©΄μμ μ½κ° κ°μ λ©λλ€ :)
graph[x].append((y, cost))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
κ΅ν©λ 리뷰 λ³΄κ³ μ λ νλ‘μ΄λ-μμ
λ°©μμΌλ‘ νμ΄ λ΄€λλ°μ,
μ μλ μκ³ λ¦¬μ¦ λ
ΈνΈμ μ€λͺ
μ΄ μλμ΄ μμ΄μ μ°Έκ³ νμ΅λλ€!
μ½λ
#include <stdio.h>
#define INF 987654321
int map[1001][1001];
void floydWarshall(int N)
{
// λͺ¨λ μ μ μμ κ²μ¬νμ¬ μ΅λ¨ 거리 κ°±μ
for (int k = 1; k <= N; k++)
{
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
if (map[i][j] > map[i][k] + map[k][j])
{
map[i][j] = map[i][k] + map[k][j];
}
}
}
}
}
int main(void)
{
int N, M;
// μ μ μ μ Nκ³Ό κ°μ μ μ Mμ μ
λ ₯λ°μ
scanf("%d", &N);
scanf("%d", &M);
// 맡 λ°°μ΄ μ΄κΈ°ν: μκΈ° μμ μΌλ‘μ 거리λ 0, κ·Έ μΈλ INFλ‘ μ€μ
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
if (i == j)
map[i][j] = 0;
else
map[i][j] = INF;
}
}
int start, end, weight;
// κ°μ μ 보 μ
λ ₯λ°μ 맡 λ°°μ΄μ λ°μ
for (int i = 0; i < M; i++)
{
scanf("%d %d %d", &start, &end, &weight);
if (map[start][end] > weight)
{
map[start][end] = weight;
}
}
floydWarshall(N);
int start, end;
scanf("%d %d", &start, &end);
// μ΅λ¨ 거리 μΆλ ₯
printf("%d\n", map[start][end]);
return 0;
}
μ λ μμ§ cλ‘ κ΅¬ννλ κ² νΈν΄μ cλ‘ νμ΄ λ΄€λλ° forλ¬Έμ 3μ€ μ€μ²©μΌλ‘ λͺ¨λ μ μ μ κ°μ μ΅λ¨ 거리λ₯Ό ꡬνλ€ λ³΄λ μμ μκ° μ΄κ³Ό κ°^^......;; γ γ νμ΄μ¬μΌλ‘ λ€μ νμ΄ λ΄μΌκ² μ΅λλ€... νκ² λλ©΄ 리뷰 λ€μ λ¨κΈΈκ²μ! μκ³ νμ ¨μ΄μ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλ
μ»΄λ€ μνμ λ€μ΅μ€νΈλΌ μκ³ λ¦¬μ¦μ΄ λμμλλ°, μ€λλ§μ 보λκΉ λ κ°λ¬Όκ°λ¬Όνλ€μ.
λΉμμλ μ§μ ꡬνν΄λ³΄μ§λ μμμλλ°, μ΄λ²μ μνλ PR κ³κΈ°λ‘ ꡬνν΄λ³΄λκΉ ν λ§νλ€μ.
μ λ μ‘°κΈλ§ μλ€κ° λ€μ΅μ€νΈλΌλ, νλ‘μ΄λ-μμ
λ±λ± μκ³ λ¦¬μ¦ λ¬Έμ λ λ§μ΄ νμ΄λ΄μΌκ² λ€μ.
PR μκ³ νμ
¨μ΅λλ€π
π λ¬Έμ λ§ν¬
https://www.acmicpc.net/problem/1916
βοΈ μμλ μκ°
μ½ 2μκ°
β¨ μλ μ½λ
π©΅1. λ¬Έμ μ μ μ΄μ π©΅
π©΅2. λ€μ΅μ€νΈλΌ μκ³ λ¦¬μ¦ νμ΄π©΅
π©΅3. μ½λ μ€λͺ π©΅
π§1) ν μλ£κ΅¬μ‘°
π§2) ν λ°λ³΅ ꡬ쑰
-> λ§μ½ νμ¬ λ ΈλκΉμ§μ μ μ₯λ 거리 nodeκ° wdightλ³΄λ€ μλ€λ©΄, μ΄λ―Έ λ 짧μ κ²½λ‘κ° μ‘΄μ¬ν¨μ μλ―Έ
-> νμ¬ λ Έλλ₯Ό μ²λ¦¬ν νμx
-> ν λ°λ³΅ ꡬ쑰 μλμ κ·Έλ¦Ό μ°Έκ³ !
π©΅4. μ΅μ’ μ½λπ©΅
π μλ‘κ² μκ²λ λ΄μ©
λ€μ΅μ€νΈλΌ μκ³ λ¦¬μ¦μ λ¬Έμ λ‘λ§ νμ΄λ΄€μ§ μ½λλ‘ νΈλ €κ³ νλκΉ μ΄λ €μ λ€. κ·Έλ₯ λ¨μν μκ³ λ¦¬μ¦μ μ΄ν΄νκΈ°λ νμ§λ§, μ΄λ₯Ό μ°μ μμ νλ₯Ό μ΄μ©ν΄ νΈλ €κ³ νλ μκ°λ³΄λ€ μκ°μ΄ λ κ±Έλ Έλ€.
κ·Έλν μΈμ 리μ€νΈλ‘ μ΄κΈ°νλ₯Ό νλ λ°©λ²λ μκ² λμκ³ , λ¬Έμ λ₯Ό ν λ μΈμ λ Έλκ° μλ λΆλΆμ 무νμΌλ‘ μ μνλλ°, μ΄ λΆλΆμ μ²μλΆν° κ° λ ΈλκΉμ§μ 거리λ₯Ό 무νλλ‘ μ΄κΈ°ννλ κ²μ μκ²λμλ€.