-
Notifications
You must be signed in to change notification settings - Fork 34
/
1019-Brush-5.cpp
77 lines (56 loc) · 896 Bytes
/
1019-Brush-5.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
67
68
69
70
71
72
#include <stdio.h>
#include <limits.h>
#define INF 10000000
using namespace std;
int a[102][102];
void setup()
{
for (int i = 0; i < 101; i++) {
for(int j = 0; j < 101; j++) {
a[i][j] = INF;
}
}
}
int min(int x, int y)
{
if(x < y) {
return x;
}
return y;
}
int main()
{
int n;
int m;
int x;
int y;
int w;
int t;
scanf("%d", &t);
for(int p = 1; p <= t; p++) {
setup();
scanf("%d", &n);
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d", &x);
scanf("%d", &y);
scanf("%d", &w);
a[x][y] = min(w, a[x][y]);
}
for (int k = 1; k <= n; k++) {
for(int i = 0; i <= n; i++) {
for (int j = 0; j <=n; j++) {
if(a[i][j] > a[i][k] + a[k][j]) {
a[i][j] = a[i][k] + a[k][j];
}
}
}
}
if(a[1][n] != INF) {
printf("Case %d: %d\n",p, a[1][n]);
}
else {
printf("Case %d: Impossible\n", p);
}
}
}