1126 Eulerian Path (25分)

It has been proven that connected graphs with all vertices of even degree have an Eulerian circuit, and such graphs are called Eulerian. 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.

even 偶数,odd 奇数

Eulerian 连通图,所有顶点度为偶

semi-Eulerian 连通图,有两个顶点度为奇

判断连通图,一个深搜:

如果遍历的点的个数不等于点的总数,那么说明至少有两个连通分支,图不是连通图

void dfs(int x){
    visit[x]=true;
    cnt++;
    for(int i=0;i<v[x].size();i++){
        if(visit[v[x][i]]==false) dfs(v[x][i]);
    }
}

 

//  even degree  odd degree
#include<bits/stdc++.h>
using namespace std;
const int maxn=510;
vector<int> v[maxn];
bool visit[maxn]={false};
int cnt=0;
void dfs(int x){
    visit[x]=true;
    cnt++;
    for(int i=0;i<v[x].size();i++){
        if(visit[v[x][i]]==false) dfs(v[x][i]);
    }
}
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    while(m--){
        int x,y;
        scanf("%d %d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1);
    int odd=0,even=0;
    for(int i=1;i<=n;i++){
        if(i!=1) printf(" ");
        printf("%d",v[i].size());
        if(v[i].size()%2==0) even++;
        else odd++; 
    }
    printf("\n");
    if(even==n&&cnt==n){
        printf("Eulerian");
    }else if(odd==2&&cnt==n){
        printf("Semi-Eulerian");
    }else{
        printf("Non-Eulerian");
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值