zoukankan      html  css  js  c++  java
  • Wrestling Match---hdu5971(2016CCPC大连 染色法判断是否是二分图)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5971

    题意:有n个人,编号为1-n, 已知X个人是good,Y个人是bad,m场比赛,每场比赛都有一个good和一个bad人结合起来,问这n个人是否能被分成两种人

    其实就是判断是否为二分图,用染色法判断一下就可以了

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <algorithm>
    #include <bitset>
    #include <iostream>
    #include <time.h>
    #include <vector>
    #include <queue>
    
    typedef long long LL;
    
    using namespace std;
    
    const int N = 10265;
    const double eps = 1e-10;
    const int INF = 0x3f3f3f3f;
    const int mod = 1000000007;
    const double PI = 4*atan(1.0);
    
    int a[N], b[N], f[N];
    
    int main()
    {
        int n, m, X, Y, x;
        while(scanf("%d %d %d %d", &n, &m, &X, &Y) != EOF)
        {
            memset(f, -1, sizeof(f));
    
            for(int i=1; i<=m; i++)
                scanf("%d %d", &a[i], &b[i]);
    
            for(int i=1; i<=X; i++)
            {
                scanf("%d", &x);
                f[x] = 1;
            }
            for(int i=1; i<=Y; i++)
            {
                scanf("%d", &x);
                f[x] = 0;
            }
            int flag = 0;
            for(int i=1; i<=m; i++)
            {
                if(f[a[i]] == -1 && f[b[i]] == -1)
                    f[a[i]] = 1, f[b[i]] = 0;
                else if(f[a[i]] != -1 && f[b[i]] == -1)
                    f[b[i]] = f[a[i]]^1;
                else if(f[a[i]] == -1 && f[b[i]] != -1)
                    f[a[i]] = f[b[i]]^1;
                else if(f[a[i]] == f[b[i]] && f[a[i]]!=-1)
                    flag = 1;
            }
            for(int i=1; i<=n; i++)
            {
                if(f[i] == -1)
                    flag = 1;
            }
            if(flag) puts("NO");
            else  puts("YES");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Bash基本语法
    安装Ifconfig
    Centos6版本升级
    使用Lombok简化你的代码
    二、快速起步(Mysql镜像)
    一、Docker之旅
    logback.xml日志配置
    mybatis动态SQL标签的用法
    你不知道的Java类
    系统管理员需知的 16 个 iptables 使用技巧
  • 原文地址:https://www.cnblogs.com/zhengguiping--9876/p/6038325.html
Copyright © 2011-2022 走看看