zoukankan      html  css  js  c++  java
  • uva 11396 二分图判定

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<vector>
    #include<cstdlib>
    #include<algorithm>
    #include<queue>
    #include<map>
    #include<stack>
    
    using namespace std;
    
    #define LL long long
    #define UINT unsigned int
    #define MAX_INT 0x7fffffff
    #define cint const int
    
    #define MAXN 333
    vector<int> g[MAXN];
    int n, col[MAXN];
    
    bool dfs(int u, int color){
        col[u] = color;
        for(int i=0; i<g[u].size(); i++){
            int v = g[u][i];
            if(col[v]==col[u] || !col[v]&&!dfs(v, 3-color))
                return false;
        }
        return true;
    }
    
    int main(){
    //    freopen("C:\Users\Administrator\Desktop\in.txt","r",stdin);
        while(scanf(" %d", &n)==1 && n){
            int i, u, v;
            for(i=1; i<=n; i++) g[i].clear();
            while(scanf(" %d %d", &u, &v)==2){
                if(!v) break;
                g[u].push_back(v);
                g[v].push_back(u);
            }
            fill_n(col+1, n, 0);
            for(i=1; i<=n; i++) if(!col[i])
                if(!dfs(i, 1)) break;
            if(i<=n) printf("NO
    ");
            else printf("YES
    ");
        }
        return 0;
    }
    

    Problem B
    Claw Decomposition

    Input: Standard Input

    Output: Standard Output

    A claw is defined as a pointed curved nail on the end of each toe in birds, some reptiles, and some mammals. However, if you are a graph theory enthusiast, you may understand the following special class of graph as shown in the following figure by the word claw.

    If you are more concerned about graph theory terminology, you may want to define claw as K1,3.

    Let’s leave the definition for the moment & come to the problem. You are given a simple undirected graph in which every vertex has degree 3. You are to figure out whether the graph can be decomposed into claws or not.

    Just for the sake of clarity, a decomposition of a graph is a list of subgraphs such that each edge appears in exactly one subgraph in the list.

    Input

    There will be several cases in the input file. Each case starts with the number of vertices in the graph, V (4<=V<=300). This is followed by a list of edges. Every line in the list has two integers, a & b, the endpoints of an edge (1<=a,b<=V). The edge list ends with a line with a pair of 0. The end of input is denoted by a case with V=0. This case should not be processed.

    Output

     

    For every case in the input, print YES if the graph can be decomposed into claws & NO otherwise.

    Sample Input                                                  Output for Sample Input

    4

    1 2

    1 3

    1 4

    2 3

    2 4

    3 4

    0 0

    6

    1 2

    1 3

    1 6

    2 3

    2 5

    3 4

    4 5

    4 6

    5 6

    0 0

    0

    NO

    NO


    Problemsetter: Mohammad Mahmudur Rahman

    Special Thanks to: Manzurur Rahman Khan

     

    参考:http://blog.csdn.net/wiking__acm/article/details/8739684

    。。。。题意都不大懂,先挖个坑。。。虽然A了。。。
  • 相关阅读:
    【阿里前端面试点】目标,想成为一名好的前端工程师
    JavaScript实现数据双向绑定的三种方式
    a标签的下载链接,如果是图片,点击链接是下载一个图片而不是直接打开,应该怎么办?(添加download属性)
    AngularJs scope详解
    setTimeout可以传第三个甚至更多个参数
    (转) css3中的border-radius详解
    (转) JS原生对象、内置对象、宿主对象的区别
    纯css写的步骤条
    css如何实现滚动条隐藏但鼠标仍然可以滚动
    Js 与浮点数
  • 原文地址:https://www.cnblogs.com/ramanujan/p/3378705.html
Copyright © 2011-2022 走看看