交叉染色法判定二分图
来源:互联网 发布:嵌入式linux笔试题 编辑:程序博客网 时间:2024/04/30 00:32
Divide Groups
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 916 Accepted Submission(s): 322
Problem Description
This year is the 60th anniversary of NJUST, and to make the celebration more colorful, Tom200 is going to invite distinguished alumnus back to visit and take photos.
After carefully planning, Tom200 announced his activity plan, one that contains two characters:
1. Whether the effect of the event are good or bad has nothing to do with the number of people join in.
2. The more people joining in one activity know each other, the more interesting the activity will be. Therefore, the best state is that, everyone knows each other.
The event appeals to a great number of alumnus, and Tom200 finds that they may not know each other or may just unilaterally recognize others. To improve the activities effects, Tom200 has to divide all those who signed up into groups to take part in the activity at different time. As we know, one's energy is limited, and Tom200 can hold activity twice. Tom200 already knows the relationship of each two person, but he cannot divide them because the number is too large.
Now Tom200 turns to you for help. Given the information, can you tell if it is possible to complete the dividing mission to make the two activity in best state.
Input
The input contains several test cases, terminated by EOF.
Each case starts with a positive integer n (2<=n<=100), which means the number of people joining in the event.
N lines follow. The i-th line contains some integers which are the id
of students that the i-th student knows, terminated by 0. And the id starts from 1.
Each case starts with a positive integer n (2<=n<=100), which means the number of people joining in the event.
N lines follow. The i-th line contains some integers which are the id
of students that the i-th student knows, terminated by 0. And the id starts from 1.
Output
If divided successfully, please output "YES" in a line, else output "NO".
Sample Input
33 01 01 2 0
Sample Output
YES
裸题。。。。
/***************************************** author:crazy_石头* algorithm:交叉染色法判定二分图* date:2013/10/17* 条件:* 1、不存在环* 2、图是连通图* 3、双向图*思路:*任意取一个点进行染色,如果发现要涂某一块时这个块已经被涂了色,并且与我们要使用的颜色不同的话,就说明这个图不能被染成BICOLORABLE的。*(1)如果没有染色,将它染色,并将它周围的点变成相反色。*(2)如果已经染色,判断是否与现在染色的点的颜色相同,相同,则退出,否则继续。*****************************************/#pragma comment(linker, "/STACK:1024000000,1024000000")#include<cstdio>#include<cstring>#include<climits>using namespace std;#define N 90005#define M 4000005#define INF INT_MAXconst int maxn=100+10;int map[maxn][maxn];int cnt;int head[maxn],color[maxn];inline int max(int a,int b){ return a>b?a:b;}inline int min(int a,int b){ return a<b?a:b;}struct Edge{ int to,next;}edge[maxn*maxn];inline void addedge(int u,int v){ edge[cnt].to=v; edge[cnt].next=head[u]; head[u]=cnt++;}inline void makemap(int u,int v){ addedge(u,v); addedge(v,u);}inline bool dfs(int u,int colour){ color[u]=colour; for(int i=head[u];~i;i=edge[i].next) { int v=edge[i].to; if(color[v]!=-1) { if(color[v]==colour) return false; continue; } if(!dfs(v,!colour)) return false; } return true;}inline void init(){ cnt=0; memset(head,-1,sizeof(head)); memset(color,-1,sizeof(color));}int main(){ int n; while(~scanf("%d",&n)) { int temp; memset(map,0,sizeof(map)); for(int i=1;i<=n;i++) { while(scanf("%d",&temp)&&temp) map[i][temp]=1; } init(); for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { if(map[i][j]==0||map[j][i]==0) { makemap(i,j); } } } int ok=1; for(int i=1;i<=n;i++) { if(color[i]==-1&&!dfs(i,0)) { ok=0; break; } } ok==1?puts("YES"):puts("NO"); } return 0;}
- 交叉染色法判定二分图
- 二分图判定(染色法)
- poj2942[补图+点双连通分量+交叉染色法判定二分图(奇圈判定)]
- 交叉染色法判断二分图
- 二分图判定(染色问题)
- HDU 4751 交叉染色判断二分图
- UVA 10004 Bicoloring(二分图 交叉染色)
- CodeForce 687A 二分图 交叉染色
- 二分图匹配以及交叉染色
- poj 2942 求点双联通+二分图判断奇偶环+交叉染色法判断二分图
- hdu 2444 交叉染色判断二分图+二分最大匹配
- UVa 11396 - Claw Decomposition(二分图判定,染色法,dfs)
- 判定二分图——染色法VjP1462小胖的难题
- poj2942(双联通分量,交叉染色判二分图)
- HDU 4751 — Divide Groups 交叉染色判二分图
- Light OJ 1300 - Odd Personality (Tarjian求边双连通+二分图染色法判定奇圈)
- NOIP 2010 关押罪犯 二分答案+二分图染色判定 COGS 520
- Codeforces Round #360 (Div. 2) 前三题题解【简单模拟+思维+二分图判定二分染色】
- 【HBase】org.apache.hadoop.hbase包及其类的说明
- 磁盘管理
- 一定要努力
- Math随机数
- [Azure体验篇]Node.js on Azure Website
- 交叉染色法判定二分图
- Java解析XML四种方式
- 在CentOS6.4上,安装MySQL5.6.14
- 牛腩新闻发布系统中用到的IsPostBack属性
- 动态加载js 文件
- Github Pages域名绑定
- PDR
- The Struts dispatcher cannot be found
- XML中的五个保留字符及其实体引用