先上一个板子吧,无向的
hihocoder-1181
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e4+5;
struct E{
int to,next;
}edge[maxn<<1];
int head[maxn],tot,vis[maxn<<1],path[maxn],top;
int n,m;
void add(int u,int v){
edge[tot].to=v;
edge[tot].next=head[u];
head[u]=tot++;
}
void dfs(int u){
for(int i=head[u];i!=-1;i=edge[i].next){
if(!vis[i]){
vis[i]=1;
vis[i^1]=1;
dfs(edge[i].to);
}
}
path[top++]=u;
}
int main(){
memset(head,-1,sizeof(head));
cin>>n>>m;
for(int i=0;i<m;i++){
int u,v;cin>>u>>v;
add(u,v);add(v,u);
}
dfs(1);
for(int i=0;i<top-1;i++){
cout<<path[i]<<" ";
}
cout<<path[top-1]<<endl;
}
/*
6 7
1 2
1 4
2 3
2 6
2 5
3 4
5 6
*/
本文探讨了图论中的欧拉回路概念,重点关注无向图的情况。通过实例分析,阐述如何寻找和理解欧拉回路,并提供了一个在线平台hihocoder-1181的相关练习。

1269

被折叠的 条评论
为什么被折叠?



