-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1797.cpp
46 lines (35 loc) · 867 Bytes
/
1797.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
#include <iostream>
#include <cstdio>
using namespace std;
const int inf = 0x3fffffff;
int dis[1010][1010];
int main()
{
int test_case;
cin >> test_case;
for (int z = 0; z < test_case; ++ z)
{
cout << "Scenario #" << z + 1 << ":" << endl;
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; ++ i)
for (int j = 0; j < n; ++ j)
dis[i][j] = inf;
for (int i = 0; i < m; ++ i)
{
int temp1, temp2, temp3;
scanf("%d %d %d", &temp1, &temp2, &temp3);
dis[temp1 - 1][temp2 - 1] = dis[temp2 - 1][temp1 - 1] = temp3;
}
for (int k = 0; k < n; ++ k)
for (int i = 0;i < n; ++ i)
for (int j = 0; j < n; ++ j)
{
int min = dis[i][k] > dis[k][j] ? dis[k][j] : dis[i][k];
if (dis[i][j] != inf && min != inf && min > dis[i][j])
dis[i][j] = min;
}
printf("%d\n", dis[0][n - 1]);
}
return 0;
}