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 zhongqiaoling at 2013-11-18 15:20:11 on Problem 1182
#include<stdio.h>
#define N 50000

int st[N+100];
int rank[N+100];
int count;

int find(int i)
{
	if(st[i]==i) return i;
	st[i]=find(st[i]);
	rank[i]=(rank[i]+rank[st[i]])%3;
	return st[i];
}

void unionset(int i,int j,int d)
{
	int tp,tq;
	tp=find(i);
	tq=find(j);
	if(tp==tq){
		if((rank[j]-rank[i]+3)%3!=d)
			count++;
		return ;
	}
	st[tq]=tp;
	rank[tq]=(rank[i]-rank[j]+3+d)%3;
	return ;
}

int main(void)
{
	int i,n,m;
	int d,x,y;
	scanf("%d%d",&n,&m);
	count=0;
	for(i=0;i<n;i++){
		st[i]=i;
		rank[i]=0;
	}
	for(;m>0;m--){
		scanf("%d%d%d",&d,&x,&y);
		if(x>n||y>n)  {
			count++;
			continue;
		}
		unionset(x,y,d-1);
	}
	printf("%d\n",count);
	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