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 guoshiyuan422799 at 2016-08-25 20:48:42 on Problem 1182
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,kind[50005];
int main ()
{
	int times=0;
	cin>>n>>m;
	fill(kind,kind+n+2,0);
	for(int i=0;i<m;i++)
	{
		int d,a,b;
		cin>>d>>a>>b;
		if(a>n||b>n)
		{	times++;
		     continue;
		}
		if(d==1)
	{
		if(kind[a]==0&&kind[b]==0)
		{
			kind[a]=1;
			kind[b]=1;
		}
		if(kind[a]!=0&&kind[b]==0)
			kind[b]=kind[a];
		if(kind[b]!=0&&kind[a]==0)
			kind[a]=kind[b];
		if(kind[a]!=0&&kind[b]!=0&&kind[b]!=kind[a])
			times++;
		}
		if(d==2)
		{
			if(kind[a]!=0&&kind[b]!=0)
			{	if(kind[a]-kind[b]==-1||kind[a]-kind[b]==2)
				times=times;
			    else
				times++;
			}
			if(kind[a]!=0&&kind[b]==0)
				if(kind[a]<=2)
				kind[b]=kind[a]+1;
			else
				kind[b]=kind[a]-2;
			if(kind[b]!=0&&kind[a]==0)
			   if(kind[b]>=2)
				   kind[a]=kind[b]-1;
			   else
				   kind[a]=kind[b]+2;
			if(kind[a]==0&&kind[b]==0)
			  {    kind[a]=1;
			       kind[b]=2;
			   }
		}
	}
	cout<<times<<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