Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

又是WA,是否forms 之间的路径是有向的??

Posted by blue1000 at 2007-07-30 10:51:06 on Problem 2395
用的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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator