题目链接

题目大意是说输入数字n

然后告诉你第i个人都认识谁?

让你把这些人分成两堆,使这每个堆里的人都互相认识。

做法:把不是互相认识的人建立一条边,则构建二分图,两堆的人肯定都互相认识,也就是说,互相认识的两个人肯定不相连。

——代码

 #include <cstdio>
#include <cstring> using namespace std; int n, cnt;
int head[], to[], next[], color[];
bool know[][]; void add(int x, int y)
{
to[cnt] = y;
next[cnt] = head[x];
head[x] = cnt++;
}
//把点染成1或-1
bool dfs(int u, int c)
{
int i, v;
color[u] = c;
for(i = head[u]; i != - ; i = next[i])
{
v = to[i];
if(color[v] == c) return ;
if(color[v] == && !dfs(v, -c)) return ;
}
return ;
} bool solve()
{
int i;
for(i = ; i <= n; i++)
if(color[i] == && !dfs(i, ))
return ;
return ;
} int main()
{
int i, j, x;
while(~scanf("%d", &n))
{
memset(know, , sizeof(know));
memset(color, , sizeof(color));
for(i = ; i <= n; i++)
while(scanf("%d", &x) && x)
know[i][x] = ;
memset(head, -, sizeof(head));
for(i = ; i <= n; i++)
for(j = i + ; j <= n; j++)
if(!know[i][j] || !know[j][i])
{
add(i, j);
add(j, i);
}
if(solve()) printf("YES\n");
else printf("NO\n");
}
return ;
}

最新文章

  1. 轻松3步实现c#windowsform窗体美化
  2. google的云盘与公司网盘
  3. @synthesize obj = _obj 理解
  4. 从一个标准URL中提取文件的扩展名
  5. JAVA中的deflate压缩实现
  6. javascript写的新闻滚动代码
  7. Proud Merchants(POJ 3466 01背包+排序)
  8. Composer更新慢的解决方案
  9. Java基础随记-不定时更新
  10. js的简单介绍
  11. python自动化测试入门篇-jemter
  12. Kubernetes 安装
  13. MySQL 关于索引那点事
  14. maven POM.xml内的标签大全详解
  15. “融而开放、合以创新”T-HIM融合通信技术开发实战
  16. 【mysql】测试方案整理
  17. 嵌入式驱动开发之uboot---uboot 中的常见命令参数参数
  18. java轻量级IOC框架Guice(转)
  19. 牛客网提高组模拟赛第七场 T3 洞穴(附bitset介绍)
  20. 1 如何使用pb文件保存和恢复模型进行迁移学习(学习Tensorflow 实战google深度学习框架)

热门文章

  1. 裸机(Bare Metal)安装CoreOS
  2. 【经验】css
  3. 手把手教你webpack、react和node.js环境配置(下篇)
  4. 关于redis 缓存的问题
  5. python学习笔记(一)元组tuple
  6. (八)javaScript对象简介
  7. (1)写给Web初学者的教案-----学习Web的知识架构
  8. Mybatis的@Options注解
  9. 如何在RecyclerView上面实现&quot;拖放&quot;和&quot;滑动删除&quot;-1
  10. Untiy文档总结(1)-Profiling