-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path그래프_11404_플로이드.cpp
66 lines (55 loc) · 1.08 KB
/
그래프_11404_플로이드.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <algorithm>
#define CITY_MAX 100
#define INF 1000000
using namespace std;
int cityArr[CITY_MAX + 1][CITY_MAX + 1];
int cityNum, busNum;
int cost, s, e;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> cityNum >> busNum;
for (int i = 0; i < busNum; i++)
{
cin >> s >> e >> cost;
if (cityArr[s][e] == 0)
cityArr[s][e] = cost;
else
cityArr[s][e] = min(cityArr[s][e], cost);
}
for (int i = 1; i < cityNum + 1; i++)
{
for (int j = 1; j < cityNum + 1; j++)
{
if (cityArr[i][j] == 0)
cityArr[i][j] = INF;
}
}
for (int cnt = 1; cnt < cityNum; cnt++)
{
for (int i = 1; i < cityNum + 1; i++)
{
for (int j = 1; j < cityNum + 1; j++)
{
if (i == j)
cityArr[i][j] = 0;
else
for (int k = 1; k < cityNum + 1; k++)
cityArr[i][j] = min(cityArr[i][j], cityArr[i][k] + cityArr[k][j]);
}
}
}
for (int i = 1; i < cityNum + 1; i++)
{
for (int j = 1; j < cityNum + 1; j++)
{
if (cityArr[i][j] == INF)
cout << "0 ";
else
cout << cityArr[i][j] << " ";
}
cout << endl;
}
}