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 mountainhigh at 2011-05-05 22:26:44 on Problem 3321 and last updated at 2011-05-05 22:47:50
#include<iostream>
#include<cstring>
using namespace std;
int N,M;
struct fork
{
	int parent,num,flag;
}c[100100];
int main()
{
	int i,j,x,y,lj;
	char q;
	cin>>N;
	for(i=1;i<=N;i++)
	{
		c[i].parent=0;
		c[i].num=1;
		c[i].flag=1;
	}
	for(i=0;i<N-1;i++)
	{
		cin>>x>>y;
		if(x>y)
		{
			int chang;
			chang=x;x=y;y=chang;
		}
		c[y].parent=x;
		lj=x;
		while(c[lj].parent)
		{
		    c[lj].num+=c[y].num;
			lj=c[lj].parent;
		}
		c[1].num+=c[y].num;
	}
	cin>>M;
	for(i=0;i<M;i++)
	{
		cin>>q;
		cin>>j;
		if(q=='Q')
			cout<<c[j].num<<endl;
		else
		{
			if(c[j].flag==1)
			{
				c[j].flag=0;
				lj=j;
				while(c[lj].parent)
				{
					c[lj].num--;
					lj=c[lj].parent;
				}
				c[1].num--;
			}
			else
		    {
				c[j].flag=1;
				lj=j;
				while(c[lj].parent)
				{
					c[lj].num++;
					lj=c[lj].parent;
				}
			    c[1].num++;
		    }
		}
	}
	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