hdu4715
题解:
二分图判断
建立原图的补图
判断是否是二分图
代码:
#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的更多相关文章
随机推荐
- POJ_1195 Mobile phones 【二维树状数组】
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013912596/article/details/33802561 题目链接:id=1195&qu ...
- kotlin写的几个小例子
Kotlin-AdapterDemo kotlin语言下BaseAdapter,ArrayAdapter,SimpleAdapter,SimpleCursorAdapter四种适配器的示例 工具and ...
- 在python列表中删除所有空元素
今天在测试数据的时候偶然发现一个问题,如下: test = ['a','','b','','c','',''] for i in test: if i == '': test.remove(i) pr ...
- 快速入门Python中文件读写IO是如何来操作外部数据的?
读写文件是最常见的IO操作.Python内置了读写文件的函数,用法和C是兼容的. 读写文件前,我们先必须了解一下,在磁盘上读写文件的功能都是由操作系统提供的,现代操作系统不允许普通的程序直接操作磁盘, ...
- PHP 多字节字符串 函数
参考资料 多字节字符编码方案和他们相关的问题相当复杂,超越了本文档的范围. 关于这些话题的更多信息请参考以下 URL 和其他资源. Unicode materials » http://www.uni ...
- Storm--命令行解析
strom的命令行解析 Commands: activate classpath deactivate dev-zookeeper drpc help jar kill list localconfv ...
- INFO hdfs.DFSClient: Exception in createBlockOutputStream java.net解决办法
自己安装好Hadoop2.7.x之后,发现dfs中的/bin/hadoop fs -put命令不能够使用,报错如下: [hadoop@master bin]$ ./hadoop fs -put ../ ...
- linux centos7 安装zookeeper
linux 系统下 zookeeper 安装教程 1.下载安装包 1)进入安装目录 cd /home/install/ 2)下载 wget http://mirror.bit.edu.cn/apach ...
- 用python实现0到9之间10个数字排列不重复的个数
""" product 笛卡尔积 permutations 排列 combinations 组合,没有重复 combinations_with_replacement ...
- Mysql字段属性应该尽量设置为not null
除非你有一个很特别的原因去使用 NULL 值,你应该总是让你的字段保持 NOT NULL.这看起来好像有点争议,请往下看. 所谓的NULL就是什么都没有,连\0都没有,\0在字符串中是结束符,但是在物 ...