-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuva-11015.cpp
60 lines (48 loc) · 1.08 KB
/
uva-11015.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
//uva 11015
//05-2 Rendezvous
#include <iostream>
#include <vector>
#include <string>
#include <climits>
using namespace std;
int main(void)
{
int n, m;
int tcounter = 0;
while(true){
cin >> n >> m;
if(n == 0 && m == 0) break;
++tcounter;
vector <string> people(n);
for(int i = 0; i < n; ++i)
cin >> people[i];
vector <vector <int> > Graph(n, vector <int> (n, INT_MAX));
for(int i = 0; i < n; ++i)
Graph[i][i] = 0;
for(int i = 0; i < m; ++i){
int u, v, value;
cin >> u >> v >> value;
--u, --v;
Graph[u][v] = value;
Graph[v][u] = value;
}
for(int k = 0; k < n; ++k)
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
if(Graph[i][k] != INT_MAX && Graph[k][j] != INT_MAX)
Graph[i][j] = min(Graph[i][k] + Graph[k][j], Graph[i][j]);
int minDist = INT_MAX;
string person;
for(int i = 0; i < n; ++i){
int cost = 0;
for(int j = 0; j < n; ++j)
cost += Graph[i][j];
if(minDist > cost){
minDist = cost;
person = people[i];
}
}
cout << "Case #" << tcounter << " : " << person << endl;
}
return 0;
}