• UVA


    题目大意:给你一张无向图,每一个点的度数都是3。

    你的任务是推断是否能把它分解成若干个爪(每条边仅仅能属于一个爪)

    解题思路:二分图染色裸题。能够得出:爪的中心点和旁边的三个点的颜色是不一样的

    #include <cstdio>
    #include <cstring>
    using namespace std;
    #define N 310
    #define M 2010
    
    struct Edge{
        int to, Next;
    }E[M];
    int head[N], color[N], tot;
    int n, m;
    
    void AddEdge(int from, int to) {
        E[tot].to = to;
        E[tot].Next = head[from];
        head[from] = tot++;
    }
    
    void init() {
        memset(head, -1, sizeof(head));
        tot = 0;
    
        int u, v;
        while (scanf("%d%d", &u, &v) && u + v) {
            AddEdge(u, v);
            AddEdge(v, u);
        }
    }
    
    bool bipartite(int u) {
        for (int i = head[u]; i != -1; i = E[i].Next) {
            int v = E[i].to;
            if (color[v] == color[u])
                return false;
            if (!color[v]) {
                color[v] = 3 - color[u];
                if (!bipartite(v))
                    return false;
            }
        }
        return true;
    }
    
    void solve() {
        memset(color, 0, sizeof(color));
        color[1] = 1;
        if (bipartite(1))
            printf("YES
    ");
        else
            printf("NO
    ");
    }
    
    int main() {
        while (scanf("%d", &n) != EOF && n) {
            init();
            solve();
        }
        return 0;
    }
    
  • 相关阅读:
    UILabel 详解
    didMoveToSuperView 引发的思考
    Source
    设计模式
    Code ReView
    UIApearance
    UINavigationBar
    initWithNibName与viewDidLoad的执行关系以及顺序
    bLock 回调 就是这么简单!
    程序语言小记
  • 原文地址:https://www.cnblogs.com/zsychanpin/p/7196948.html
Copyright © 2020-2023  润新知