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 |
又是WA,是否forms 之间的路径是有向的??用的prim #include<iostream> using namespace std; int f(int c[][2001],int n){ int i,j,k,min,max; int *d=new int[n+2]; char *nvd = new char[n+1]; memset(nvd,1,sizeof(nvd)); for(i=0;i<=n+1;i++) d[i]=INT_MAX; min=1; max=0; k=1; nvd[1]=0; for(i=1;k<n;i=min){ min=n+1; for(j=1;j<=n;j++){ if(nvd[j] && c[i][j]<d[j]) d[j]=c[i][j]; if(nvd[j] && d[j]<d[min]) min=j; } max=max>d[min]?max:d[min]; k++; nvd[min]=0; } return max; } int v[2001][2001]; int main(){ int a,b,L,n,m,i,j; cin>>n>>m; for(i=1;i<=n;i++) for(j=1;j<=n;j++) v[i][j]=INT_MAX; for(i=0;i<m;i++){ scanf("%ld%ld%ld",&a,&b,&L); if(L<v[a][b]) v[b][a]=v[a][b]=L; } printf("%ld\n",f(v,n)); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator