| ||||||||||
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 |
为何W了。。。。。。。求帮忙。。。。#include <iostream> #include <stdio.h> #include <cstring> using namespace std; const int maxn=150; const int inf=0x7fffffff; int map[maxn][maxn],dist[maxn]; bool visit[maxn],flag[maxn][maxn]; int n,m; void prim(){ memset(flag,false,sizeof(flag)); int mini,pos,result=0,Pos,minresult,maxedge; for(int i=1;i<=n;++i){ dist[i]=map[1][i]; visit[i]=false; } visit[1]=true; for(int i=1;i<n;++i){ mini=inf; for(int j=1;j<=n;++j){ if(!visit[j]&&dist[j]<mini){ pos=j; mini=dist[j]; flag[i][j]=true; } } visit[pos]=true; result+=dist[pos]; for(int j=1;j<=n;++j){ if(!visit[j]&&map[pos][j]<dist[j]){ dist[j]=map[pos][j]; } } } int aa=result; bool f=false; for(int i=1;i<=n;++i){ for(int j=i+1;j<=n;++j){ minresult=result; if(flag[i][j]==true) continue; else{ flag[i][j]=true; Pos=j; for(int j=i;j<=Pos;++j){ maxedge=max(dist[j],0); } minresult-=maxedge; minresult+=map[i][Pos]; if(minresult==aa){ f=true; break; } } } } if(f) cout<<"Not Unique!"<<endl; else cout<<aa<<endl; } int main() { // freopen("in.txt","r",stdin); int N; scanf("%d",&N); while(N--){ memset(map,0x7f,sizeof(map)); scanf("%d%d",&n,&m); for(int i=1;i<=m;++i){ int x,y,value; scanf("%d%d%d",&x,&y,&value); map[x][y]=map[y][x]=value; } 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