/* Bismillahir Rahmanir Rahim
Solution-Using "Floyd Warshall"
*/
#include<bits/stdc++.h>
#define fi(n, m) for(int i=n; i<=m; i++)
#define fd(n, m) for(int i=n; i>=m; i--)
using namespace std;
int main(){
int cs=1, n, u, v, w, m;
string s;
while(1){
int i, j, k, dis[25][25], ans, sum, mn=1000000009;
map<int, string>mp;
cin>>n>>m;
if(n==0) break;
fi(1, n){
cin>>s;
mp[i]=s;
}
for(i=1; i<=n; i++){
for(j=1; j<=n; j++){
if(i==j)dis[i][j]=0;
else dis[i][j]=1000000009;
}
}
fi(0, m-1){
cin>>u>>v>>w;
dis[u][v]=dis[v][u]=w;
}
for(k=1; k<=n; k++){
for(i=1; i<=n; i++){
for(j=1; j<=n; j++){
dis[i][j]=min(dis[i][j], (dis[i][k]+dis[k][j]));
}
}
}
for(i=1; i<=n; i++){
sum=0;
for(j=1; j<=n; j++){
sum=sum+dis[i][j];
}
if(mn>sum){
mn=sum; ans=i;
}
}
cout<<"Case #"<<cs++<<" : "<<mp[ans]<<endl;
}
return 0;
}
|
Wednesday, March 1, 2017
Solution of UVa 11015 - 05-2 Rendezvous
Subscribe to:
Post Comments (Atom)
-
#include<bits/stdc++.h> #define ll long long using namespace std ; ll n , k , t_case ; ll bigmod ( ll b , ll p , ll m...
-
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 ...
-
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 3...
No comments:
Post a Comment