#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 10010;
const int M = 50010;
/* 题意:在欧拉图中求一条每条边经过两次的路径,可理解为双向的欧拉回路*/
struct Node{
int to,nex;
}edge[M*2];
int head[N];
int cnt;
bool vis[M*2];
void add(int x,int y){
edge[cnt].to = y;
edge[cnt].nex = head[x];
head[x] = cnt++;
}
void dfs(int now){
for(int i=head[now]; i!=-1; i=edge[i].nex){
if(!vis[i]){
vis[i] = true;
dfs(edge[i].to);
}
}
printf("%d\n",now);
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m)){
memset(head,-1,sizeof(head));
memset(vis,false,sizeof(vis));
cnt = 0;
int a,b;
while(m--){
scanf("%d%d",&a,&b);
add(a,b);
add(b,a);
}
dfs(1);
}
return 0;
}
【欧拉回路】poj 2230 Watchcow
最新推荐文章于 2024-09-16 07:45:00 发布