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

tle?!!怎么回事呀?

Posted by Headacher at 2009-05-01 15:06:24 on Problem 3687
#include<iostream>
using namespace std;
int n,m,a,b,cas;
int map[201][201];
int in[201];
int list[201];
bool v[201],flag=0;
int solve(int cnt)
{
	int i,j;
	if(flag==1)
			return 0;
	if(cnt==n&&!flag)
	{
		for(i=n-1;i>=1;i--)
		{
			printf("%d ",list[i]);
		}
		printf("%d\n",list[i]);
		flag=1;
		return 0;
	}
	for(i=n;i>=1;i--)
	{
		if(in[i]==0&&!v[i])
		{	
			list[cnt]=i;
			v[i]=1;
			for(j=1;j<=n;j++)
			{
				if(map[i][j])
				{
					in[j]--;
				}
			}
			solve(cnt+1);
			if(flag==1)
				return 0;
			for(j=1;j<=n;j++)
			{
				if(map[i][j])
				{
					in[j]++;
				}
			}
			v[i]=0;
		}
	}
	return 0;
}
int main()
{
	int i,j;
	scanf("%d",&cas);
	while(cas--)
	{
		flag=0;
		printf("\n");
		memset(in,0,sizeof(in));
		memset(map,0,sizeof(map));
		memset(v,0,sizeof(v));
		memset(list,0,sizeof(list));
		scanf("%d%d",&n,&m);
		while(m--)
		{
			scanf("%d%d",&a,&b);
			if(map[b][a]==0)
			{	

				map[b][a]=1;
				in[a]++;
			}
		}
		solve(0);
		if(!flag)
			printf("-1\n");
		
	}
	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