-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuva-10048.cpp
More file actions
59 lines (48 loc) · 988 Bytes
/
uva-10048.cpp
File metadata and controls
59 lines (48 loc) · 988 Bytes
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
//uva 10048
//Audiophobia
#include <iostream>
#include <climits>
#include <vector>
#include <map>
using namespace std;
int main(void)
{
int c, s, q;
int tcounter = 0;
bool first = 0;
while(true){
cin >> c >> s >> q;
if(c == 0 && s == 0 && q == 0)
break;
++tcounter;
if(first)
cout << endl;
first = 1;
vector < vector <int> > Graph(c, vector <int> (c, INT_MAX));
for(int i = 0; i < c; ++i)
Graph[i][i] = 0;
for(int i = 0; i < s; ++i){
int u, v, val;
cin >> u >> v >> val;
--u;
--v;
Graph[u][v] = Graph[v][u] = min(Graph[u][v], val);
}
for(int k = 0; k < c; ++k)
for(int i = 0; i < c; ++i)
for(int j = 0; j < c; ++j)
Graph[i][j] = min(Graph[i][j], max(Graph[i][k], Graph[k][j]));
cout << "Case #" << tcounter << endl;
for(int i = 0; i < q; ++i){
int u, v;
cin >> u >> v;
--u;
--v;
if(Graph[u][v] != INT_MAX)
cout << Graph[u][v] << endl;
else
cout << "no path" << endl;
}
}
return 0;
}