[POJ 2492] A Bug's Life [黑白染色]
来源:互联网 发布:sift python 编辑:程序博客网 时间:2024/05/16 14:32
有一些虫子,已知谁和谁是不同性别的,问有没有矛盾
可以使用扩展并查集
也可以先构造出整个图,然后黑白染色,看他是不是二分图,这里用的黑白染色
#include <cstdio>#include <cstring>using namespace std;struct Node {int fe,col;};struct Edge {int t,ne;};bool ans;int n,m,p;Node a[2100];Edge b[2000100];void putedge(int x,int y) {b[p].t=y;b[p].ne=a[x].fe;a[x].fe=p;p++;}void dfs(int i,int c) {if (a[i].col==-c) ans=false;if (a[i].col!=0) return;a[i].col=c;c=-c;for (int j=a[i].fe;j;j=b[j].ne) {dfs(b[j].t,c);}}int main() {int t,tt,i,x,y;ans=true;scanf("%d",&t);for (tt=1;tt<=t;tt++) {memset(a,0,sizeof(a));p=1;scanf("%d%d",&n,&m);for (i=0;i<m;i++) {scanf("%d%d",&x,&y);putedge(x,y);putedge(y,x);}ans=true;for (i=1;i<=n&&ans;i++) {if (a[i].col==0) dfs(i,1);}printf("Scenario #%d:\n",tt);if (ans) printf("No suspicious bugs found!\n");else printf("Suspicious bugs found!\n");printf("\n");}return 0;}
0 0
- [POJ 2492] A Bug's Life [黑白染色]
- HDU1829 A Bug's Life dfs黑白染色二分图
- POJ 2492 A Bug's Life【二分图染色法】
- HDU1829&POJ 2492 a bug's life [并查集||二分图染色]
- poj 2492 A Bug's Life(并查集 染色法 二分图)
- poj 2492 A Bug's Life
- POJ-2492 A Bug's Life
- Poj 2492 A Bug's Life
- poj 2492 A Bug's Life
- POJ 2492 - A Bug's Life
- POJ 2492 A Bug's Life
- POJ-2492-A Bug's Life
- poj 2492 A Bug's Life
- poj 2492 A Bug's Life
- poj 2492 A Bug's Life
- POJ 2492 A Bug's Life
- poj 2492 A Bug's Life
- POJ-2492-A Bug's Life
- ubuntu中vi上下左右键显示字母的解决方法
- Action中result的各种转发类型
- POJ-1273
- 图像采样
- 最大连续乘积字串
- [POJ 2492] A Bug's Life [黑白染色]
- C++设计新思维(1)
- Java笔记:抽象类
- codeforces A. Shaass and Oskols 题解
- 关于i++和++i的问题 -----具体到比较纠结的i=(i++)+(i++)问题
- 在VMware虚拟机上安装Ubuntu 10.04 (网址)
- fzoj 2170 花生的序列
- VMware Workstation 7.1注册机(序列号/注册码)
- Agri-Net 1558 Agri-Net