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

贴一份较短ac代码,水过,1235ms

Posted by xc19881023 at 2016-04-25 14:35:29 on Problem 2230
#include <cstdio>
const int maxN=10005,maxM=100005;
struct arc
{
	int from,to,nxt,vis;
}g[maxM];
int n,m,eg,head[maxN];

void add_arc(int i,int j)
{
	g[++eg].from=i,g[eg].to=j,g[eg].nxt=head[i],g[eg].vis=0,head[i]=eg;
}

void dfs(int i)
{
	for (int j = head[i]; j ; j=g[j].nxt)
	{
		if (!g[j].vis)
		{
			g[j].vis=1;
			dfs(g[j].to);
			printf("%d\n",g[j].to);
		}
	}
}

int main()
{
//	freopen("D:\\input.txt","r",stdin);
	scanf("%d%d",&n,&m);
	while (m--)
	{
		int i,j;
		scanf("%d%d",&i,&j);
		add_arc(i,j),add_arc(j,i);
	}
	dfs(1);
	puts("1");
	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