Monday, August 25, 2014

uva :544 - Heavy Cargo

#include<cstdio>
#include<iostream>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    int i,j,k,l,m,n,vertex,road,y=0;
    while(scanf("%d %d",&vertex,&road)==2)
    {
        if((vertex+road)==0)break;
        int graph[vertex+1][vertex+1];
        for (i=1;i<=vertex;i++)
        {
            for(j=1;j<=vertex;j++)
            graph[i][j]=0;
        }
        int c=1;
        string s1,s2;
        map<string, int>number;
        for(i=0;i<road;i++)
        {
            cin >> s1 >> s2 >> n;
            if(number[s1]==0)number[s1]=c++;
            if(number[s2]==0)number[s2]=c++;
            j=number[s1];
            k=number[s2];
            graph[j][k]=n;
            graph[k][j]=n;
        }
        for(int k=1;k<=vertex;k++)
        {
            for(int i=1;i<=vertex;i++)
            {
                for(int j=1;j<=vertex;j++)
                {
                    graph[i][j]=max(graph[i][j],min(graph[i][k],graph[k][j]));
                }
            }
        }
        cin >> s1 >> s2;
        cout << "Scenario #" << ++y << endl;
        cout << graph[number[s1]][number[s2]]<<" tons" << endl << endl;
    }
    return 0;
}

No comments:

Post a Comment