HDU——T 2444 The Accomodation of Students
http://acm.hdu.edu.cn/showproblem.php?pid=2444
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7087 Accepted Submission(s): 3168
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.
1 2
1 3
1 4
2 3
6 5
1 2
1 3
1 4
2 5
3 6
3
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue> using namespace std; const int N();
int n,m,head[N],sumedge;
struct Edge
{
int v,next;
Edge(int v=,int next=):v(v),next(next){}
}edge[];
inline void ins(int u,int v)
{
edge[++sumedge]=Edge(v,head[u]);
head[u]=sumedge;
edge[++sumedge]=Edge(u,head[v]);
head[v]=sumedge;
} int col[N];
bool Paint(int x)
{
col[x]=;
queue<int>que;
que.push(x);
for(int u,v;!que.empty();)
{
u=que.front(); que.pop();
for(int i=head[u];i;i=edge[i].next)
{
v=edge[i].v;
if(col[v]!=-)
{
if(col[v]==col[u])
return false;
}
else
{
col[v]=col[u]^;
que.push(v);
}
}
}
return true;
} int sumvis,vis[N],match[N],Map[N][N];
bool find(int u)
{
/*for(int v,i=head[i];i;i=edge[i].next)
{
v=edge[i].v;
if(!vis[v])
{
vis[v]=1;
if(!match[v]||find(match[v]))
{
match[v]=u;
return true;
}
}
}*/
for(int v=;v<=n;v++)
if(Map[u][v]&&!vis[v])
{
vis[v]=;
if(!match[v]||find(match[v]))
{
match[v]=u;
return true;
}
}
return false;
} inline void init()
{
memset(edge,,sizeof(edge));
memset(head,,sizeof(head));
memset(match,,sizeof(match));
} int main()
{
for(;~scanf("%d%d",&n,&m);init())
{
int ans=,flag=;sumvis=;
memset(Map,,sizeof(Map));
for(int u,v;m--;ins(u,v))
scanf("%d%d",&u,&v),Map[u][v]=;
memset(col,-,sizeof(col));
for(int i=;i<=n;i++)
if(col[i]==-)
if(!Paint(i))
{
flag=;
break;
}
if(flag)
{
puts("No");
continue;
}
for(int i=;i<=n;i++)
{
if(find(i)) ans++;
memset(vis,,sizeof(vis));
}
printf("%d\n",ans);
}
return ;
}
HDU——T 2444 The Accomodation of Students的更多相关文章
- (hdu)2444 The Accomodation of Students 判断二分图+最大匹配数
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2444 Problem Description There are a group of s ...
- hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)
http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS Me ...
- HDU 2444 The Accomodation of Students 二分图判定+最大匹配
题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...
- hdu 2444 The Accomodation of Students 判断二分图+二分匹配
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 2444 The Accomodation of Students(判断二分图+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU——2444 The Accomodation of Students
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 2444 The Accomodation of Students (判断二分图,最大匹配)
The Accomodation of StudentsTime Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- hdu 2444 The Accomodation of Students(二分匹配 匈牙利算法 邻接表实现)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDOJ 2444 The Accomodation of Students
染色判读二分图+Hungary匹配 The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limi ...
随机推荐
- Vue中的坑
今天给大家总结了Vue中的坑,都是平常踩到的,希望对大家有所帮助 1.vuex的一个“坑” 报错原因:在使用Vuex的时候在main.js中引入的时候对名字的大小写有区别 解决法案: 错误写法: 正确 ...
- KVM虚拟机相关步骤
KVM是Kernel-based Virtual Machine的简称,是一个开源的虚拟化模块,该文档是基于CentOS 7.4环境操作的 一.操作系统安装 本文采用的是CentOS 7.4 1.查看 ...
- python--(爬虫-re模块)
python--(爬虫-re模块) re模块四大核心功能: 1.findall 查找所有,返回list import re lst = re.findall("m", " ...
- ./configure --prefix /?/? 解释
-- ./configure :编译源码 --prefix :把所有资源文件放在 之后的路径之后
- .get(),eq()的区别
.get(),eq()的区别 eq:返回是一个jquery对象作用是将匹配的元素集合缩减为一个元素.这个元素在匹配元素集合中的位置变为0,而集合长度变成1. get:是一个html对象数组作用是取得其 ...
- Vue轮播图插件---Vue-Awesome-Swiper
轮播图插件 Vue-Awesome-Swiper 地址:https://github.com/surmon-china/vue-awesome-swiper 安装:npm install vue-aw ...
- Spring+Mybatis+SpringMVC后台与前台分页展示实例
摘要:本文实现了一个后台由spring+Mybatis+SpringMVC组成,分页采用PageHelper,前台展示使用bootstrap-paginator来显示效果的分页实例.整个项目由mave ...
- angular-数据库
<div ng-app="myApp" ng-controller="customersCtrl"> <table> <tr ng ...
- 洛谷 P3912 素数个数
P3912 素数个数 题目描述 求1,2,\cdots,N1,2,⋯,N 中素数的个数. 输入输出格式 输入格式: 1 个整数NN. 输出格式: 1 个整数,表示素数的个数. 输入输出样例 输入样例# ...
- Compiler Warning (level 2) CS0436
https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0436 // CS0436_a.cs // compile with: /target:l ...