【PAT】1126 Eulerian Path (25 分)

区别连通相邻

题中已知无向图

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值