标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3263 Accepted Submission(s): 1018
#include <iostream> #include <cstring> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <time.h> #include <string> #include <map> #include <stack> #include <vector> #include <set> #include <queue> #define inf 0x3f3f3f3f #define mod 1000000007 typedef long long ll; using namespace std; const int N=5000+5; map<string,int>mp; int n,c,r,w[110][110]; void floyd() { for(int k=1; k<=n; k++) for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) { if(w[i][j]>w[i][k]+w[k][j]) w[i][j]=w[i][k]+w[k][j]; } } int main() { char a[50],b[50],t[30]; char d[1010][110],ch2,ch1; int k,cas=1,kl; while(scanf("%d%d%d",&n,&r,&c)!=EOF) { k=1; if(n==0&&r==0&&c==0) break; mp.clear(); for(int i=0; i<110; i++) for(int j=0; j<110; j++) if(i==j) w[i][j]=0; else w[i][j]=inf; for(int i=0; i<=r; i++) { scanf("%s",&d[i]); if(mp[d[i]]==0) mp[d[i]]=k++; } for(int ii=0; ii<c; ii++) { scanf("%s",&a); scanf(" %c-%d-%c ",&ch1,&kl,&ch2); scanf("%s",&b); if(mp[a]==0) mp[a]=k++; if(mp[b]==0) mp[b]=k++; int u=mp[a],v=mp[b]; if(ch1==‘<‘) w[v][u]=min(kl,w[v][u]); if(ch2==‘>‘) w[u][v]=min(kl,w[u][v]); } floyd(); int sum=0; for(int i=1; i<=r; i++) { sum+=w[mp[d[0]]][mp[d[i]]]+w[mp[d[i]]][mp[d[0]]]; } printf("%d. %d\n",cas++,sum); } }
HDU2923 Einbahnstrasse (Floyd)
标签:
原文地址:http://www.cnblogs.com/jianrenfang/p/5723241.html