BNUOJ 1585 Girls and Boys
Girls and Boys
This problem will be judged on PKU. Original ID: 1466
64-bit integer IO format: %lld Java class name: Main
Input
the number of students
the description of each student, in the following format
student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
or
student_identifier:(0)
The student_identifier is an integer number between 0 and n-1 (n <=500 ), for n subjects.
Output
Sample Input
7
0: (3) 4 5 6
1: (2) 4 6
2: (0)
3: (0)
4: (2) 0 1
5: (1) 0
6: (2) 0 1
3
0: (2) 1 2
1: (1) 0
2: (1) 0
Sample Output
5
2
Source
解题:找出相互没关系的一个人数最大的集合。首先,是点!让点多,我们可以求点小!最小点覆盖!那么我们可以求最大匹配数!无向图的最大匹配数要处以2.。。。就这样了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc{
int to,next;
};
arc g[];
int head[maxn],from[maxn],tot,n;
bool vis[maxn];
void add(int u,int v){
g[tot].to = v;
g[tot].next = head[u];
head[u] = tot++;
}
bool dfs(int u){
for(int i = head[u]; i != -; i = g[i].next){
if(!vis[g[i].to]){
vis[g[i].to] = true;
if(from[g[i].to] == - || dfs(from[g[i].to])){
from[g[i].to] = u;
return true;
}
} }
return false;
}
int main() {
int i,j,k,u,v,ans;
while(~scanf("%d",&n)){
memset(head,-,sizeof(head));
memset(from,-,sizeof(from));
tot = ;
for(i = ; i < n; i++){
scanf("%d: (%d)",&j,&k);
for(j = ; j < k; j++){
scanf("%d",&v);
add(i,v);
add(v,i);
}
}
for(ans = i = ; i < n; i++){
memset(vis,false,sizeof(vis));
if(dfs(i)) ans++;
}
ans >>= ;
printf("%d\n",n-ans);
}
return ;
}
BNUOJ 1585 Girls and Boys的更多相关文章
- POJ 1466 Girls and Boys
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- Girls and Boys
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hduoj-----(1068)Girls and Boys(二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ Girls and Boys (最大独立点集)
Girls and Boys Time Limit: 5000MS Memo ...
- poj 1466 Girls and Boys(二分图的最大独立集)
http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submis ...
- hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 网络流(最大独立点集):POJ 1466 Girls and Boys
Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...
- Girls and Boys(匈牙利)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- (hdu step 6.3.2)Girls and Boys(比赛离开后几个人求不匹配,与邻接矩阵)
称号: Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- [ZPG TEST 115] 字符串【归类思想】
pdf效果太差,转成word效果依旧差,只好转成jpg传了. 这一题用到了“归类”的思想,令s(i, a)表示前i个字体,字符a出现的次数.那么ans一定等于一个 ( s(i, a) - s(j, ...
- 51nod 1098 最小方差
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; ty ...
- js和 php 介绍
转 1. 在公司项目的改造当中,经常会遇到js与php的函数互调的情况,而实际上JS与php的设计者是不提倡这两种语言直接进行调用的,一个是客户端语言,一个服务端语言,两者之间的交互往往靠的是ajax ...
- Join方法,yield方法,线程的优先级
- Android开发学习——简单类图
1.类A继承于类B (B 是父类,A是 子类) 2.小汽车.自行车 实现车的接口 3.A中有B这个成员变量,单向关联 4.聚合,整体与部分的关系.has-a B中的构造函数(或set方法)需要 ...
- 原创 SqlParameter 事务 批量数据插入
不错,很好,以后防注入批量事务提交虽然麻烦点研究了几个小时,但不会是问题了 SqlCommand cmd; HelpSqlServer helps = new HelpSqlServer(); //定 ...
- 30款jQuery常用网页焦点图banner图片切换
1.jquery 图片滚动特效制作 slide 图片类似窗帘式图片滚动 查看演示 2.jquery幻灯片插件带滚动条的圆形立体图片旋转滚动 查看演示 3.jQuery图片层叠旋转类似洗牌翻转图片幻灯片 ...
- git ---合并和删除分支
git merge 分支名 //合并子分支到当前分支 git branch -d 分支名//删除分支
- 浅谈CSS中的定位知识
1,静态定位(static) 表示按照正常定位方案,元素盒按照在文档流中出现的顺序依次格式化: 2,相对定位(relative) 将移动元素盒,但是它在文档流中的原始空间会保留下来: 相对定位元素有如 ...
- python mail
转载一个不错python mail封装 #!/usr/bin/python from email.MIMEText import MIMEText from email.MIMEMultipart i ...