【模板】无向图欧拉回路和欧拉路径判断

博客内容提及题面,版子不多讲,还给出了转载链接https://www.cnblogs.com/ainiyuling/p/11188149.html 。

题面

版子不多讲

#include <iostream>
#include <cstring>
using namespace std;
const int MAX_N = 100;
const int MAX_M = 10000;
struct edge {
    int v, next;
    int len;
} E[MAX_M];
int p[MAX_N], eid;
void init() {
    memset(p, -1, sizeof(p));
    eid = 0;
}
void insert(int u, int v) {
    E[eid].v = v;
    E[eid].next = p[u];
    p[u] = eid++;
}

int n,m;
int degree[MAX_N];

int euler(){
    int first = 0,last = 0;
    for(int i = 1;i <= n;i++){
        if(degree[i]<-1 || degree[i] > 1){
            cout<<"It doesn't have an euler path!"<<endl;
            return 0;
        }else if(degree[i] == -1){
            if(first != 0){
                cout<<"It doesn't have an euler path!"<<endl;
                return 0;
            }else{
                first = i;
            }
        }else if(degree[i] == 1){
            if(last != 0 ){
                cout<<"It doesn't have an euler path!"<<endl;
                return 0;
            }else{
                last = i;
            }
        }
    }
    if(first == 0 && last == 0){
        cout<<"It has an eluer circuit!"<<endl;
        return 1;
    }else if(first != 0 && last != 0){
        cout<<"It has an euler path!"<<endl;
        return first;
    }
}

int main() {
    init();
    memset(degree,0,sizeof(degree));
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        insert(u,v);
        degree[u]--;
        degree[v]++;
    }
    euler();
    return 0;
}

  

转载于:https://www.cnblogs.com/ainiyuling/p/11188149.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值