题目大意:
求有向图欧拉路径的点序列。
解题思路:
欧拉回路模板。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<ctime>
#include<bitset>
#define LL long long
#define db double
#define EPS 1e-15
#define inf 1e10
#define pa pair<int,int>
using namespace std;
const int maxn=50010;
struct edge{
int to,next,w;
bool flag;
}e[2*maxn];
int ans[2*maxn],head[2*maxn],cnt=0,ansi=0;
void prepare(){
memset(head,-1,sizeof(head));
}
void add(int u,int v,int w){
e[cnt].to=v; e[cnt].next=head[u]; e[cnt].flag=0; head[u]=cnt++;
e[cnt].to=u; e[cnt].next=head[v]; e[cnt].flag=0; head[v]=cnt++;
}
void dfs(int now){
for (int k=head[now];k!=-1;k=e[k].next){
if (!e[k].flag){
e[k].flag=1;
dfs(e[k].to);
}
}
ans[ansi++]=now;
}
int main(){
int n,m,u,v;
prepare();
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++){
scanf("%d%d",&u,&v);
add(u,v,1);
}
dfs(1);
for (int i=ansi-1;i>=0;i--) printf("%d\n",ans[i]);
return 0;
}