forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
10048.cpp
80 lines (75 loc) · 1005 Bytes
/
10048.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
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>
using namespace std;
#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a > b ? b : a)
#define INF 21474836
#define MAXN 102
int N, M, Q, A[MAXN][MAXN];
void Floyd()
{
int i, j, k;
for (k = 1; k <= N; k++)
{
for (i = 1; i <= N; i++)
{
for (j = 1; j <= N; j++)
{
A[i][j] = MIN(A[i][j], MAX(A[i][k], A[k][j]));
}
}
}
}
void Cal()
{
int a, b;
Floyd();
while (Q--)
{
scanf("%d%d", &a, &b);
if (A[a][b] == INF)
{
printf("no path\n");
}
else
{
printf("%d\n", A[a][b]);
}
}
}
void INI()
{
int i, j;
for (i = 1; i <= N; i++)
{
for (j = 1; j <= N; j++)
{
A[i][j] = INF;
}
A[i][i] = 0;
}
}
int main()
{
int i, kase = 1;
int a, b, c;
while (scanf("%d%d%d", &N, &M, &Q) == 3)
{
if (!N && !M && !Q)
{
break;
}
INI();
for (i = 0; i < M; i++)
{
scanf("%d%d%d", &a, &b, &c);
A[a][b] = A[b][a] = c;
}
if (kase > 1)
{
putchar('\n');
}
printf("Case #%d\n", kase++);
Cal();
}
return 0;
}