Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
数据太弱了。这样的程序也能A(有数据为证,明显not unique)/*********数据*****/ 1 4 4 1 2 3 2 3 1 3 4 3 4 1 1 /*********数据*****/ #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> using namespace std; #define N 105 #define INF 99999999 int map[N][N]; int dis[N]; int visit[N]; int n; void prim() { int i,j,v,min,k,flag,sum; for(i=1;i<=n;i++) dis[i]=map[1][i]; flag=0; sum=0; memset(visit,0,sizeof(visit)); for(i=1;i<=n;i++) { min=INF; for(j=1;j<=n;j++) if(!visit[j]&&dis[j]<min) { min=dis[j]; v=j; } k=0; for(j=1;j<=n;j++) if(visit[j]&&map[v][j]==min) k++; if(k>1) { flag=1; break; } visit[v]=1; sum+=min; for(j=1;j<=n;j++) if(!visit[j]&&dis[j]>map[v][j]) dis[j]=map[v][j]; } if(flag) printf("Not Unique!\n"); else printf("%d\n",sum); } int main() { int t; int i,j,m; int a,b,c; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(i=1;i<=n;i++) for(j=1;j<=n;j++) { map[i][j]=INF; if(i==j) map[i][j]=0; } while(m--) { scanf("%d%d%d",&a,&b,&c); if(map[a][b]>c) { map[a][b]=map[b][a]=c; } } prim(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator