hdu 4751 Divide Groups 染色

    建个反向图,染个色,一切不言而喻

   今天比赛一直把题目想复杂,没改题前先求了重联通图,改题后又试了极大团,2sat等等。还是基础不牢,概念不清

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <vector>
using namespace std;
int n;
int MM[101][101];
int org[101][101];
int color[101];
int dfs(int v,int c)
{
    if(!color[v])color[v]=c;
    else
    {
        if(color[v]==c)return 0;
        else return 1;
    }
    for(int i=1;i<=n;i++)
        if(org[v][i]&&v!=i)
            if(dfs(i,-c))return 1;
    return 0;
}
int solve()
{
    memset(color,0,sizeof(color));
    for(int i=1;i<=n;i++)
        if(!color[i])
            if(dfs(i,1))return 0;
    return 1;
}
int main()
{
    int i,j;
    while(~scanf("%d",&n))
    {
        int t;
        memset(MM,0,sizeof(MM));
        for(i=1; i<=n; i++)
            while(~scanf("%d",&t)&&t)
                MM[i][t]=1;
        memset(org,0,sizeof(org));
        for(i=1;i<=n;i++)
            for(j=i;j<=n;j++)
            if(!MM[i][j]||!MM[j][i])
                org[i][j]=org[j][i]=1;
        if(solve())puts("YES");
        else puts("NO");
    }
}
时间: 2024-09-27 01:10:40

hdu 4751 Divide Groups 染色的相关文章

hdu4751Divide Groups(dfs枚举完全图集合或者bfs染色)

/************************************************************************* > File Name: j.cpp > Author: HJZ > Mail: 2570230521@qq.com > Created Time: 2014年08月28日 星期四 12时26分13秒 *******************************************************************

hdu 3306 Another kind of Fibonacci

点击此处即可传送hdu 3306 **Another kind of Fibonacci** Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2005 Accepted Submission(s): 787 Problem Description As we all known , the Fibonacci series : F(0) =

hdu 1588 Gauss Fibonacci

点击此处即可传送hdu 1588 **Gauss Fibonacci** Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2849 Accepted Submission(s): 1179 Problem Description Without expecting, Angel replied quickly.She says: "I'v h

hdu 5364 Distribution money

hdu 5364 的传送门 Problem Description AFA want to distribution her money to somebody.She divide her money into n same parts.One who want to get the money can get more than one part.But if one man's money is more than the sum of all others'.He shoule be p

hdu 1021 Fibonacci Again

点击此处即可传送hdu 1021 Fibonacci Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 44439 Accepted Submission(s): 21214 Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1)

hdu 1527

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1527 hint:威佐夫博弈 基本类似于模板 #include <iostream> #include <cmath> #include <cstdio> using namespace std; const double q = (1 + sqrt(5.0)) / 2.0; // 黄金分割数 int Wythoff(int a, int b) { if (a > b)

hdu 2551 竹青遍野

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2551 hint:就是读懂题就行了 #include <iostream> #include <cstdio> using namespace std; typedef long long LL; LL data[1005]; int main() { data[0]=0; for(int i=1; i<1005; i++) data[i]+=data[i-1]+i*i*i; LL

hdu 2054 A == B?

http://acm.hdu.edu.cn/showproblem.php?pid=2054 此题巨坑,刚开始我以为是简单的水题,就用strcmp过, but错了,后来经过我苦思冥想,结果还有几组数据 0.0 和 0,1.000和1.0 , 但是我不太确定前面的0是不是有作用我还是写了,但是有人过的时候,前面的0没考虑比如: 002和2可能是相等的,也可能是不想等的所以不用判断,只能说明hdu数据不是很强啊,嘿嘿 代码如下: #include <iostream> #include <c

hdu 4430 Yukari&#039;s Birthday

点击打开链接hdu 4430 思路:枚举r+二分k 分析: 1 题目要求的是找到一组最小的r*k,如果r*k相同那么就找r最小的. 2 很明显k>=2,根据n <= 10^12,那么可以知道r的最大值r<50,所以只要枚举枚举r的值,然后二分k的大小找到所有的解,存入一个结构体里面,然后在对结构体排序,那么这样就可以得到最后的ans 3 注意题目说了中心点最多一个蜡烛,所以写二分的时候应该注意判断的条件: 4 还有可能计算得到结果超了long long直接变成负数所以应该对或则个进行判断