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的让人不可原谅啊

Posted by 1559007285 at 2011-08-09 00:24:23 on Problem 1611
#include<iostream>
#include<string.h>
#include<memory.h>
#include<stdio.h>
using namespace std;
int parent[40000];
int find(int x)
{
   if(parent[x]<0)return x;
   else  find(parent[x]);
}
void Union(int root1,int root2)
{
	int x=find(root1);
	int y=find(root2);
	if(x==y)return;
	if(parent[x]<=parent[y])
	{
		parent[x]+=parent[y];
		parent[y]=x;
	}
	else
	{
		parent[y]+=parent[x];
		parent[x]=y;
	}
}

int main()
{
	int ti,zu,n,y,x,num;
	int i,j,k;
	while(scanf("%d%d",&ti,&zu)!=EOF)
	{
		if(ti==0&&zu==0)break;
		for(i=0;i<ti;i++)
			parent[i]=-1;
		for(i=0;i<zu;i++)
		{
			scanf("%d",&n);
			if(n)scanf("%d",&x);
			for(j=1;j<n;j++)
			{
               scanf("%d",&y);
			   Union(x,y);
			   
			}
		}
		
		cout<<0-parent[find(0)]<<endl;
	}
	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