题解:

二分图判断

建立原图的补图

判断是否是二分图

代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int an[N],ans,a[N][N],n,x;
void dfs(int x,int y)
{
if (ans)return;
an[x]=y;
for (int i=;i<=n;i++)
if ((!a[x][i]||!a[i][x])&&i!=x)
{
if (an[i]&&-y!=an[i]){ans=;return;}
if (!an[i])dfs(i,-y);
}
}
int main()
{
while (~scanf("%d",&n))
{
ans=;
memset(an,,sizeof an);
memset(a,,sizeof a);
for (int i=;i<=n;i++)
for (scanf("%d",&x);x;scanf("%d",&x))a[i][x]=;
for (int i=;i<=n;i++)
if (!an[i])dfs(i,);
if (ans)puts("NO");else puts("YES");
}
}

hdu4715的更多相关文章

随机推荐

  1. Angular学习笔记—创建一个angular项目

    开始项目前,你需要先安装node和npm,然后执行npm install -g @angular/cli安装Angular CLI. 如何安装node.js和npm npm使用介绍 1.安装angul ...

  2. Digital Audio - Creating a WAV (RIFF) file

    Abstract:This tutorial covers the creation of a WAV (RIFF) audio file. It covers bit size, sample ra ...

  3. linux 或c 时间相关处理类型和函数

    注意1.精确级别,纳秒级别原型long  clock_gettime (clockid_t which_clock, struct timespec *tp); 头文件time.hwhich_cloc ...

  4. apache错误 Unable to open process" with PID 4!

    今天打开Apache的时候报错: 22:15:30  [Apache] Problem detected! 22:15:30  [Apache] Port 80 in use by "Una ...

  5. CNN学习笔记:全连接层

    CNN学习笔记:全连接层 全连接层 全连接层在整个网络卷积神经网络中起到“分类器”的作用.如果说卷积层.池化层和激活函数等操作是将原始数据映射到隐层特征空间的话,全连接层则起到将学到的特征表示映射到样 ...

  6. HDOJ 1238 Substrings 【最长公共子串】

    HDOJ 1238 Substrings [最长公共子串] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  7. ruby安装神器rvm,你造吗?

    以前的一篇文章介绍过如何安装ruby,叫做:如何安装/更新ruby,安装cocoapods,为开发做好准备!(2016年12月07日更新内容) 文章中讲到的方法依然可行,但是该方法繁琐并且可能会出现各 ...

  8. js原型 作用域

    了解JavaScript原型链之前首先肯定要知道什么是原型. JavaScript中,原型是一个对象,通过原型可以实现属性的继承.既然原型是一个对象,那么任何一个对象都可以称为原型吗?是,记住它.什么 ...

  9. AMBA总线基础知识简介

    AMBA:Advanced Microcontroller Bus Architecture,是ARMA公司的片内互联总线协议. 1995 - AMBA1.0 APB外设总线及ASB系统总线发布. 1 ...

  10. 安装 SPRING TOOL SUITE