hdu 1829 A Bug's Life
来源:互联网 发布:用友u8安装数据库 编辑:程序博客网 时间:2024/06/05 18:01
http://acm.hdu.edu.cn/showproblem.php?pid=1829
准确点说应该是读入的这对数x,y,到树根的距离的奇偶性是不可以相同的,因为如果他们到根的奇偶性相同,就说明他们是同性
搜别人的博客,别人都说这是道水题,可是我还是不会,好伤心伤心#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <cstdlib>#include <limits>#include <queue>#include <stack>#include <vector>#include <map>using namespace std;#define N 125000#define INF 0x3f3f3f3f#define PI acos (-1.0)#define EPS 1e-8int n, m, f[N], r[N];int Find (int x){ int t = f[x]; if (x != f[x]) { f[x] = Find (f[x]); r[x] = (r[x] + r[t]) % 2; } return f[x];}int main (){ int t, k = 1; cin >> t; while (t--) { cin >> n >> m; for (int i=1; i<=n; i++) { f[i] = i; r[i] = 0; } int a, b, flag = 1; for (int i=0; i<m; i++) { cin >> a >> b; int x = Find (a), y = Find (b); if (x == y) { if (r[a] == r[b])//性别相同 flag = 0; } else { f[x] = y;//性别不同,就把两个归为一个根节点 r[x] = (r[a] + r[b] + 1) % 2; } } cout << "Scenario #" << k++ << ':' << endl; if (!flag) cout << "Suspicious bugs found!" << endl; else cout << "No suspicious bugs found!" << endl; cout << endl; } return 0;}
0 0
- hdu 1829 A Bug's Life
- HDU 1829 A Bug's Life
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- hdu 1829 A bug’s life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- A Bug's Life-HDU-1829
- 陈力:传智播客古代 珍宝币 泡泡龙游戏开发第31讲:PHP面向对象程序设计(成员方法)
- hdu5256序列严格递增
- 网络流模板
- 记录wcslen,strlen,sizeof,_coutof等的用法和区别
- http协议详解
- hdu 1829 A Bug's Life
- 程序在内存中的分布
- iOS开发学习笔记三 —— Reveal
- 函数式、响应式编程 - ReactiveCocoa 快速入门
- 解决POI读取Excel内存溢出的问题
- 5分钟完成网吧服务器系统所有安装,够快了吧!
- Linux信号量
- 一切成功源于积累——20150723 大数据分析 201501-201507 所有的亏损源于五分钟定律
- ifconfig: ioctl 0x8914 failed: Cannot assign requested address