来源poj1068

In the second year of the university somebody started a study on the romantic relations between the students. The relation "romantically involved" is defined between one girl and one boy. For the study reasons it is necessary to find out the maximum set satisfying the condition: there are no two students in the set who have been "romantically involved". The result of the program is the number of students in such a set.

Input

The input contains several data sets in text format. Each data set represents one set of subjects of the study, with the following description:

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

For each given data set, the program should write to standard output a line containing the result.

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

最大独立集合,但要男女,而男女没有给出,所以会重复,要除2;点数-最大匹配数/2

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=1005;
int n,m,x,y;
int pre[N],line[N][N],visit[N],connect[N];
bool find(int x)
{
rep(i,1,n+1)
{
if(visit[i]==0&&line[x][i])
{
visit[i]=1;
if((pre[i]==0||find(pre[i]))&&pre[i]!=x)
{
pre[i]=x;
return true;
}
}
}
return false;
}
//int deal()
//{
// int ans=0;
// rep(i,1,n+1)
// {
// if(pre[pre[i]]==i)
// {
// ans++;
// pre[i]=-1;
// }
// }
// return ans;
//}
int main()
{
while(~sf("%d",&n))
{
mm(line,0);
mm(pre,0);
rep(i,1,n+1)
{
int p;
sf("%d: (%d)",&x,&p);
while(p--)
{
sf("%d",&y);
line[x+1][y+1]=1;
}
}
int ans=0;
rep(i,1,n+1)
{
mm(visit,0);
if(find(i)) ans++;
}
ans/=2;
// ans+=deal();
pf("%d\n",n-ans);
}
return 0;
}

Q - Girls and Boys的更多相关文章

  1. 网络流(最大独立点集):POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...

  2. POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...

  3. Girls and Boys

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. hduoj-----(1068)Girls and Boys(二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. POJ Girls and Boys (最大独立点集)

                                                                Girls and Boys Time Limit: 5000MS   Memo ...

  6. poj 1466 Girls and Boys(二分图的最大独立集)

    http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submis ...

  7. hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. Girls and Boys(匈牙利)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. (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 ...

随机推荐

  1. bootstrap-3-fileinput上传案例

    效果 导入的js和css <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/ ...

  2. JAVA中的ZoneId常用值备注

    一.获取代码 @Test public void zonesTest() { for (String availableZoneId : ZoneId.getAvailableZoneIds()) { ...

  3. Substr与mb_substr区别

      <?php $str = substr('helloword',3,4);//从下标3开始截取截取4个字符 $str = substr('helloword',3);//从截取掉前三个字符 ...

  4. gdb fabs错误输出

    https://sourceware.org/gdb/wiki/FAQ GDB doesn't know the return type nor the type of the arguments f ...

  5. PHPStrom激活方法

    直接用浏览器打开 http://idea.lanyus.com/ 点击页面中的“获得注册码”, 然后在注册时切换至Activation Code选项,输入获得的注册码一长串字符串 如果提示红字体信息, ...

  6. Java 连接MongoDB集群的几种方式

    先决条件 先运行mongodb肯定是必须的,然后导入以下包: import com.mongodb.MongoClient; import com.mongodb.MongoClientURI; im ...

  7. SQL DDL 数据定义语句

    前言 DDL(Data Definition Language)语句:数据定义语句,这些语句定义了不同的数据段.数据库.表.列.索引等数据库对象.常用的语句关键字主要包括 create.drop.al ...

  8. kalman滤波

    kalman滤波原理(通俗易懂) 1. 在学习卡尔曼滤波器之前,首先看看为什么叫“卡尔曼”.跟其他著名的理论(例如傅立叶变换,泰勒级数等等)一样,卡尔曼也是一个人的名字,而跟他们不同的是,他是个现代人 ...

  9. NetCore指令集和

    1.查看当前目录的版本号 C:\Users\Administrator>dotnet --version 1.0.4 2.发布程式,进入到指定目录 dotnet publish 3.运行程式 # ...

  10. Gradle 离线 安装

    第一步:下载gradle zip 文件 第二步:打开文件夹,例如:C:\Users\Administrator.gradle\wrapper\dists\gradle-3.3-all\55gk2rcm ...