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 Algorithmer at 2013-11-17 13:43:24 on Problem 2367
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	const int maxn = 200;

	int n,val,num;
	while(cin>>n && n)
	{
		num = n;
		int idx=0;
		vector<int> g[maxn];
		while (n--)
		{
			idx++;
			while(cin>>val && val)
				g[idx].push_back(val);	
		}

		queue<int> que;
		//int *rudu = new int[num+1];
		//memset(rudu,0,sizeof(rudu));

		int rudu[maxn];memset(rudu,0,sizeof(rudu));

		for (int i = 1 ; i <= num ; i++ )
			for (int j = 0 ; j< g[i].size() ; j++)
				rudu[g[i][j]]++;

		//for (int i=1 ; i<=num ; i++)
		//	cout<<rudu[i]<<" ";
		//cout<<endl;

		for (int i=1 ; i<=num ; i++)
		{
			if (rudu[i]==0)
			{
				que.push(i);
				break;
			}
		}

		int tmp;
		while(!que.empty())
		{
			tmp = que.front();
			cout<<tmp;
			que.pop();
			for (int i = 0 ; i< g[tmp].size(); i++)
				if(--rudu[g[tmp][i]] == 0 )
				{que.push(g[tmp][i]);cout<<" ";}
		}

		cout<<endl;

	}

	//system("pause");
	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