区别连通和相邻
题中已知无向图
If there are exactly two vertices of odd degree, all Eulerian paths start at one of them and end at the other.
A graph that has an Eulerian path but not an Eulerian circuit is called semi-Eulerian.
当有两个顶点的度是奇数时,所有的欧拉路径都从一点到另一点【说明只有一条欧拉路径】
当只有一条欧拉路径且不是欧拉环时,是semi-Eulerian。
综合一下,连通图,当有且仅有两个顶点的度是奇数时,是semi-Eulerian
#include <bits/stdc++.h>
using namespace std;
//欧拉路径:访问且仅访问每个结点一次
//欧拉环:起点=终点的欧拉路径
//Eulerian:连通图,所有结点偶数度 ->有一个欧拉环
//semi-Eulerian:两个结点奇数度,其中一个是起点,一个是终点
#define maxn 520
vector<int> G[maxn];
int visited[maxn];
int cnt=0;
void dfs(int root){
visited[root]=1;
cnt++;
for(int i=0;i<G[root].size();i++){
if(visited[G[root][i]]==0) dfs(G[root][i]);
}
}
int main(){
int n,m;
cin>>n>>m;
int t1,t2;
for(int i=0;i<m;i++){
cin>>t1>>t2;
G[t1].push_back(t2);
G[t2].push_back(t1);
}
int cnt_even=0;
for(int i=1;i<=n;i++){
if(i==n)cout<<G[i].size()<<endl;
else cout<<G[i].size()<<" ";
if((int)G[i].size()%2==0) cnt_even++;
}
dfs(1);//是否连通
if(cnt_even==n && cnt==n)
cout<<"Eulerian";
else if(cnt_even==n-2 && cnt==n)
cout<<"Semi-Eulerian";
else
cout<<"Non-Eulerian";
return 0;
}
本文探讨了无向图中的欧拉路径和欧拉环的概念,强调当图中有且仅有两个奇数度的顶点时,存在一条唯一的欧拉路径,这种图被称为半欧拉图。通过C++代码展示了如何判断一个图是否为欧拉图或半欧拉图。程序首先计算每个节点的度数,然后使用深度优先搜索判断图的连通性。最后,根据节点的度数和连通性状态,确定图的类型。
1239

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



