zoukankan      html  css  js  c++  java
  • poj 2263 Heavy Cargo(floyd)

    floyd

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<string>
    #include<map>
    #include<iostream>
    using namespace std;
    int n,m,edge[250][250],vis[250],dist[250];
    map<string,int>a;
    
    void floyd()
    {
        int i,j,k,t;
        for(k=1; k<=n; k++)
            for(i=1; i<=n; i++)
                for(j=1; j<=n; j++)
                {
                    if(edge[i][k]==-1||edge[k][j]==-1) continue;
                    t=min(edge[i][k],edge[k][j]);
                    if(edge[i][j]==-1) edge[i][j]=t;
                    else if(edge[i][j]<t) edge[i][j]=t;
                }
    }
    
    int main()
    {
        int i,j,tot,st,ed,cas=0,u,v,w;
        string s1,s2;
        while(~scanf("%d%d",&n,&m))
        {
            memset(edge,0,sizeof(edge));
            if(n==0&&m==0) break;
            a.clear();
            tot=1;
            for(i=0; i<m; i++)
            {
                cin>>s1>>s2>>w;
                if(a[s1]==0)
                {
                    a[s1]=tot;
                    tot++;
                }
                if(a[s2]==0)
                {
                    a[s2]=tot;
                    tot++;
                }
                u=a[s1];
                v=a[s2];
                edge[u][v]=w;
                edge[v][u]=w;
            }
            for(i=1; i<=n; i++)
                for(j=1; j<=n; j++)
                {
                    if(edge[i][j]==0) edge[i][j]=-1;
                }
            cin>>s1>>s2;
            st=a[s1];
            ed=a[s2];
            floyd();
            printf("Scenario #%d
    ",++cas);
            printf("%d tons
    
    ",edge[st][ed]);
        }
        return 0;
    }
    

    版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

  • 相关阅读:
    mongodb
    python中读取文件的read、readline、readlines方法区别
    uva 129 Krypton Factor
    hdu 4734
    hdu 5182 PM2.5
    hdu 5179 beautiful number
    hdu 5178 pairs
    hdu 5176 The Experience of Love
    hdu 5175 Misaki's Kiss again
    hdu 5174 Ferries Wheel
  • 原文地址:https://www.cnblogs.com/xryz/p/4847955.html
Copyright © 2011-2022 走看看