The Accomodation of Students (着色法)
来源:互联网 发布:mac cosmetics美国官网 编辑:程序博客网 时间:2024/05/19 12:27
There are a group of students. Some of them may know each other, while others don't. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each other.
Now you are given all pairs of students who know each other. Your task is to divide the students into two groups so that any two students in the same group don't know each other.If this goal can be achieved, then arrange them into double rooms. Remember, only paris appearing in the previous given set can live in the same room, which means only known students can live in the same room.
Calculate the maximum number of pairs that can be arranged into these double rooms.
Now you are given all pairs of students who know each other. Your task is to divide the students into two groups so that any two students in the same group don't know each other.If this goal can be achieved, then arrange them into double rooms. Remember, only paris appearing in the previous given set can live in the same room, which means only known students can live in the same room.
Calculate the maximum number of pairs that can be arranged into these double rooms.
The first line gives two integers, n and m(1<n<=200), indicating there are n students and m pairs of students who know each other. The next m lines give such pairs.
Proceed to the end of file.
4 41 21 31 42 36 51 21 31 42 53 6
No3
#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>using namespace std;int n,m;int a[220][220];int v[220];int p[220];int flag;void dfs(int x)//着色{ for(int i=1;i<=n;i++) { if(a[x][i]) { if(!p[i]) { p[i]=-p[x]; dfs(i); } else if(p[i]==p[x]) flag=1; if(flag) return ; } }}int fin(int u){ for(int i=1;i<=n;i++) { if(a[u][i]&&!v[i]) { v[i]=1; if(!p[i]||fin(p[i])) { p[i]=u; return 1; } } } return 0;}int main(){ while(~scanf("%d%d",&n,&m)) { int x,y; memset(a,0,sizeof(a)); memset(p,0,sizeof(p)); for(int i=1;i<=m;i++) { scanf("%d%d",&x,&y); a[x][y]=1; } flag=0; p[1]=1; dfs(1); if(flag) { printf("No\n"); continue; } memset(p,0,sizeof(p)); int sum=0; for(int i=1;i<=n;i++) { memset(v,0,sizeof(v)); if(fin(i)) sum++; } printf("%d\n",sum); }}
阅读全文
0 0
- The Accomodation of Students (着色法)
- The Accomodation of Students
- The Accomodation of Students
- The Accomodation of Students
- The Accomodation of Students
- The Accomodation of Students
- The Accomodation of Students
- The Accomodation of Students (二分匹配)
- HDU2444--The Accomodation of Students
- HDU2444 The Accomodation of Students
- hdu2444 The Accomodation of Students
- hdu2444 The Accomodation of Students
- 【HDU2444】The Accomodation of Students
- The Accomodation of Students---hdu2444
- HDU2444-The Accomodation of Students
- HDU2444 The Accomodation of Students
- The Accomodation of Students HDU
- The Accomodation of Students HDU
- 生成对抗网络DCGAN+Tensorflow代码学习笔记(一)----main.py
- 域名注册和域名解析
- Android Jni 利用transpose()和flip()函数实现图像旋转90°
- jQuery ajax请求错误返回status 0和错误error的问题
- 关于ICE传输文件大小的限制跟踪
- The Accomodation of Students (着色法)
- 原型模式
- [leetcode]#58. Length of Last Word
- git代码提交步骤
- 1.3.3.序列化操作
- Android 中内存泄漏的原因和解决方案
- jqueryeasyui 遮罩层mask
- hibernate 中 Provided id of the wrong type for class 异常
- 关于sql行转列的整理