zoj 1952 Heavy Cargo

/*
zoj_1952    最短路
简单题,map+dijk
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <limits.h>
#include <map>
using namespace std;
map <string,int>mp;
int road[210][210],dist[210];
bool flag[210];

int dijkstra( int sta,int end,int n )
{
    int mark,maxi,i,j;
    memset( flag,0,sizeof(flag) );
    memset( dist,0,sizeof(dist) );
    flag[sta]=1;
    dist[sta]=INT_MAX;
    for( j=1;j<n;j++ )
    {
        maxi=-1;
        for( i=0;i<n;i++ )
        {
            if( !flag[i] )
            {
                if( road[sta][i]!=0 )
                {
                    if( dist[i]==0 || dist[i]<min( dist[sta],road[sta][i] ) )
                        dist[i]=min( dist[sta],road[sta][i] );
                }
                if( maxi<dist[i] && dist[i]!=0 )
                {
                    maxi=dist[i];
                    mark=i;
                }
            }
        }
        if( maxi==-1 )  break;
        sta=mark;
        flag[sta]=1;
    }
    return dist[end];
}

int main()
{
    int n,r,i,j,v,co;
    string a,b;
    co=1;
    while( cin>>n>>r && (n || r) )
    {
        j=0;
        memset( road,0,sizeof(road) );
        for( i=0;i<r;i++ )
        {
            cin>>a>>b>>v;
            if( mp.find(a)==mp.end() ) mp[a]=j++;
            if( mp.find(b)==mp.end() ) mp[b]=j++;
            road[ mp[a] ][ mp[b] ]=v;
            road[ mp[b] ][ mp[a] ]=v;
        }
        cin>>a>>b;
        cout<<"Scenario #"<<co<<endl;
        cout<<dijkstra( mp[a],mp[b],n )<<" tons\n\n";
        co++;
        mp.clear();
    }
    return 0;
}

你可能感兴趣的:(String,ini)