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 oeym at 2006-03-19 13:14:15 on Problem 1182
In Reply To:请教大牛,我的代码什么地方错了....3X Posted by:oeym at 2006-03-19 13:09:58
> #include <stdio.h>
> #include <stdlib.h>
> #define SIZE 50010
> 
> int nd[SIZE], st[SIZE];
> int D, X, Y, cnt, hdX, hdY, N, K;
> void init()
> {
> 	int i;
> 	cnt = 0;
> 	for (i = 0; i <= N; i++)
> 	{
> 		nd[i] = st[i] = 0;
> 	}
> }
> 
> int get_id(int x)
> {
> 	int root;
> 	if (nd[x] == 0)
> 	{
> 		st[x] = 0;
> 		return x;
> 	}
> 
> 	root = get_id(nd[x]);
> 	st[x] = (st[x] + st[nd[x]]) % 3;
> 	nd[x] = root;
> 	return root;
> }
> 
> int main()
> {
> 	int i;
> 	scanf("%d%d", &N, &K);
> 	init();
> 	for (i = 0; i < K && scanf("%d%d%d", &D, &X, &Y) != -1; i++)
> 	{
> 		if (X > N || Y > N)
> 		{
> 			cnt++;
> 			continue;
> 		}
> 		if (X == Y && D == 2)
> 		{
> 			cnt++;
> 			continue;
> 		}
> 		hdX = get_id(X);
> 		hdY = get_id(Y);
> 		if (hdX != hdY)
> 		{
> 			nd[hdY] = hdX;
> 			st[hdY] = (st[X] + D + 2 - st[Y]) % 3;
> 		}
> 		else
> 		{
> 			if ((3 - st[X] + 3 - st[Y]) % 3 != D - 1)
> 			{
> 				cnt++;
> 			}
> 		}
> 	}
> 	printf("%d\n", cnt);
> 	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