How Many Maos Does the Guanxi Worth
Posted Thunder-ray
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了How Many Maos Does the Guanxi Worth相关的知识,希望对你有一定的参考价值。
代码写的很乱很乱
1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<string> 5 #include<cstdio> 6 #include<cmath> 7 using namespace std; 8 9 const int INF=0x3f3f3f3f; 10 int n,m; 11 int e[1005][1005]; 12 int dis[1005]; 13 bool vis[1005]; 14 int ee[1005]; 15 16 void init() 17 { 18 for(int i=1;i<=n;i++) 19 for(int j=1;j<=n;j++) 20 if(i==j) e[i][j]=0; 21 else e[i][j]=e[j][i]=INF; 22 for(int i=1;i<=n;i++) 23 dis[i]=INF; 24 dis[1]=0; 25 } 26 27 void di() 28 { 29 for(int i=1;i<=n;i++) 30 dis[i]=e[1][i]; 31 dis[1]=0; 32 for(int i=1;i<=n-1;i++) 33 { 34 int u; 35 int minn=INF; 36 for(int j=1;j<=n;j++) 37 { 38 if(!vis[j] && dis[j]<minn) 39 { 40 u=j; 41 minn=dis[j]; 42 } 43 } 44 45 vis[u]=1; 46 for(int j=1;j<=n;j++) 47 { 48 if(!vis[j] && dis[j]>dis[u]+e[u][j]) 49 dis[j]=dis[u]+e[u][j]; 50 } 51 } 52 } 53 54 int main() 55 { 56 while(scanf("%d%d",&n,&m)==2) 57 { 58 if(m==0&&n==0) 59 break; 60 61 init(); 62 int maxn=0; 63 int x,y,z; 64 for(int i=1;i<=m;i++) 65 { 66 scanf("%d%d%d",&x,&y,&z); 67 e[x][y]=e[y][x]=z; 68 } 69 70 for(int k=2;k<n;k++) //头和尾不能 71 { 72 for(int i=1;i<=n;i++) 73 { 74 ee[i]=e[k][i]; 75 e[k][i]=e[i][k]=INF; //断掉某一条路 76 } 77 memset(vis,0,sizeof(vis)); 78 //memset后面不能再加 vis[1]=1; 这是错的 79 di(); 80 81 if(maxn<dis[n]) 82 maxn=dis[n]; 83 for(int i=1;i<=n;i++)//还原 84 { 85 e[k][i]=e[i][k]=ee[i]; 86 } 87 } 88 if(maxn==INF) 89 printf("Inf\n"); 90 else 91 printf("%d\n",maxn); 92 } 93 }
以上是关于How Many Maos Does the Guanxi Worth的主要内容,如果未能解决你的问题,请参考以下文章
[转载] How Many Partitions Does An RDD Have
How many seconds does this period last的中文是啥
1365. How Many Numbers Are Smaller Than the Current Number
1365. How Many Numbers Are Smaller Than the Current Number
[LeetCode] 1365. How Many Numbers Are Smaller Than the Current Number
LeetCode --- 1365. How Many Numbers Are Smaller Than the Current Number 解题报告