标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 6329 | Accepted: 3925 |
Description
Input
Output
Sample Input
5 50 30 5 100 20 50 10 x x 10
Sample Output
35
Source
#include<cstdio> #include<string> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<map> #include<stdlib.h> #include<algorithm> #define LL __int64 using namespace std; const int MAXN=100+5; const int INF=0x3f3f3f3f; char str[MAXN]; int n; int w[MAXN][MAXN],d[MAXN],vis[MAXN]; void dij() { memset(vis,0,sizeof(vis)); memset(d,INF,sizeof(d)); d[1]=0; for(int i=1;i<=n;i++) { int minn=INF,tmp; for(int j=1;j<=n;j++) { if(!vis[j] && d[j]<minn) { minn=d[j]; tmp=j; } } vis[tmp]=1; for(int j=1;j<=n;j++) if(d[tmp]+w[tmp][j]<d[j]) d[j]=d[tmp]+w[tmp][j]; } int ans=-1; for(int i=2;i<=n;i++) if(d[i]>ans) ans=d[i]; printf("%d\n",ans); } int main() { //freopen("in.txt","r",stdin); while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(i!=j) w[i][j]=w[j][i]=INF; else w[i][j]=0; } } for(int i=2;i<=n;i++) { for(int j=1;j<i;j++) { scanf("%s",str); if(strcmp(str,"x")==0) w[i][j]=w[j][i]=INF; else { int tmp; sscanf(str,"%d",&tmp); w[i][j]=w[j][i]=tmp; } } } dij(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/clliff/p/4676778.html