Uva 11396 爪分解

题目链接:https://vjudge.net/contest/166461#problem/A

 

题意:

给定一个图,特点是每个点的度都是3,求是不是原图可以分解为全部鸡爪;每条边只属于一个鸡爪;

 

分析:

每一个鸡爪的根对应三个其他的顶点,但是这三个点不能再作为鸡爪的根了,

这样,两个鸡爪根就不能直接相连,这就是二分图染色,其中作为根的在一边,作为附属点的另一边;

#include <bits/stdc++.h>

using namespace std;

const int maxn = 305;
vector<int> G[maxn];
int color[maxn];

bool bipartite(int u) {
    for(int i=0;i<G[u].size();i++) {
        int v = G[u][i];
        if(color[v]==color[u])
            return false;
        if(!color[v]) {
            color[v] = 3 - color[u];
            if(!bipartite(v)) return false;
        }
    }
}

int main()
{
    int n;
    while(scanf("%d",&n),n) {
        memset(color,0,sizeof(color));

        for(int i=0;i<=n;i++)
            G[i].clear();
        int u,v;
        while(scanf("%d%d",&u,&v)) {
            if(u==0&&v==0)
                break;
            G[u].push_back(v);
            G[v].push_back(u);
        }

        color[1] = 1;
        if(bipartite(1))
            puts("YES");
        else puts("NO");

    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/TreeDream/p/6952534.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值