-
Notifications
You must be signed in to change notification settings - Fork 0
/
11015 - 05-2 Rendezvous.cpp
60 lines (59 loc) · 1.3 KB
/
11015 - 05-2 Rendezvous.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
#include<iostream>
#include<algorithm>
#include<map>
#define INT_MAX 1000000009
using namespace std;
int main()
{
int test=1;
int n,m;
int res,ans,mini=INT_MAX;
int i,j,k,u,v,w;
int graph[30][30];
string s;
while(1)
{
map<int,string>mps;
cin>>n>>m;
if(n==0)
break;
for(i=1; i<=n; i++)
{
cin>>s;
mps[i]=s;
}
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
{
if(i==j)
graph[i][j]=0;
else
graph[i][j]=INT_MAX;
}
while(m--)
{
cin>>u>>v>>w;
graph[u][v]=graph[v][u]=w;
}
for(k=1; k<=n; k++)
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
for(i=1; i<=n; i++)
{
res=0;
for(j=1; j<=n; j++)
{
res+=graph[i][j];
}
if(mini>res)
{
mini=res;
ans=i;
}
}
cout<<"Case #"<<test<<" : "<<mps[ans]<<endl;
test++;
}
return 0;
}