| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
贴一份较短ac代码,水过,1235ms#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator