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

哪错了?

Posted by 13 at 2007-04-22 17:31:35 on Problem 2578
#include<iostream.h>
#include<stdio.h>
#include<string.h>
main(){
	int m,n,a[50000]={0},b[50000]={-1},i,k,c,d,time=1;
	while(scanf("%d%d",&n,&m),n!=0&&m!=0){
		k=1;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(i=0;i<m;i++){
			scanf("%d%d",&c,&d);
			if(a[c]==0&&a[d]==0){
				a[c]=k;a[d]=1;
				b[k]+=2;
				k++;
			}
			else if(a[c]!=0&&a[d]==0)
			{a[d]=a[c];
			b[a[c]]++;
			}
			else if(a[d]!=0&&a[c]==0)
			{a[c]=a[d];
			b[a[d]]++;
			}
			else if(a[d]!=0&&a[c]!=0&&a[d]!=a[c]){
				a[d]=a[c];
				n--;
			}
		}m=0;
		for(i=1;i<k;i++)
			m+=b[i];
		printf("case %d: %d\n",time,n-k+1);
	}
	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