HDU1878欧拉回路(欧拉回路的判定)

欧拉道路:一个图的是连通的,且最多只能有2个奇点(奇点就是度数是奇数的顶点)。则此图一定存在欧拉道路。
欧拉回路:图是连通的,且没有奇度的点。
今天先开个头在这,等这段时间忙完了,在继续做风神的题集


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<cstdlib>
#define lson (rt<<1),L,M
#define rson (rt<<1|1),M+1,R
#define M ((L+R)>>1)
#define cl(a,b) memset(a,b,sizeof(a));
#define LL long long
#define P pair<int,int>
#define X first
#define Y second
#define pb push_back
#define fread(zcc)  freopen(zcc,"r",stdin)
#define fwrite(zcc) freopen(zcc,"w",stdout)
using namespace std;
const int maxn=100005;
const int inf=1<<28;

int deg[maxn];//顶点的度数
bool vis[maxn];
vector<int> G[maxn];
void dfs(int u){//判断图是不是连通的
    if(vis[u])return ;
    vis[u]=true;
    for(int i=0;i<G[u].size();i++){
        dfs(G[u][i]);
    }
}
int main(){
    int n,m;
    while(scanf("%d",&n)&&n){
        scanf("%d",&m);
        for(int i=1;i<=n;i++){
            G[i].clear();
            deg[i]=0;
            vis[i]=false;
        }
        for(int i=0;i<m;i++){
            int x,y;
            scanf("%d%d",&x,&y);
            deg[x]++;deg[y]++;
            G[x].pb(y);
            G[y].pb(x);
        }
        bool ok=true;
        for(int i=1;i<=n;i++)if(deg[i]&1){
            ok=false;break;
        }
        dfs(1);
        for(int i=1;i<=n;i++)if(!vis[i]){
            ok=false;break;
        }
        if(ok){
            puts("1");
        }
        else {
            puts("0");
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值