Hdu 1068 最小路径覆盖
Girls and Boys
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6942 Accepted Submission(s): 3118Problem Descriptionthe 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.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, for n subjects.
For each given data set, the program should write to standard output a line containing the result.Sample Input7
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) 0Sample Output5
2
/*************************************************************************
> File Name: 1068.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年07月14日 星期一 16时29分38秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int MAX_N = + ;
int n;
int cx[MAX_N], cy[MAX_N], mark[MAX_N];
vector<int> G[MAX_N]; int
path(int u) {
for (int i = ; i < (int)G[u].size(); i++) {
int v = G[u][i];
if (!mark[v]) {
mark[v] = ;
if (cy[v] == - || path(cy[v])) {
cx[u] = v;
cy[v] = u;
return ;
}
}
}
return ;
} int
MaxMatch() {
memset(cx, -, sizeof(cx));
memset(cy, -, sizeof(cy));
int res = ;
for (int i = ; i < n; i++) {
if (cx[i] == -) {
memset(mark, , sizeof(mark));
res += path(i);
}
}
return res;
} int
main(void) {
while (~scanf("%d", &n)) {
for (int i = ; i < n; i++) G[i].clear();
for (int i = ; i < n; i++) {
int a, b;
scanf("%d: (%d)", &a, &b);
for (int j = ; j < b; j++) {
int c;
scanf("%d", &c);
G[a].push_back(c);
}
}
printf("%d\n", n - MaxMatch() / );
} return ;
}
Hdu 1068 最小路径覆盖的更多相关文章
- hdu 1151 最小路径覆盖
先说说最小路径覆盖的定义 定义:在一个有向图中,找出最少的路径,使得这些路径,经过每一个点,且每一个点只与一条路径相关联, 由上面得出: 1.一个单独的点是一个路径 2:如果有路径a,b,c....f ...
- hdu 1151 Air Raid(二分图最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS Memory Limit: 10000K To ...
- HDU 6311 Cover (无向图最小路径覆盖)
HDU 6311 Cover (无向图最小路径覆盖) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- HDU 3861 The King’s Problem 最小路径覆盖(强连通分量缩点+二分图最大匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 最小路径覆盖的一篇博客:https://blog.csdn.net/qq_39627843/ar ...
- 缩点+最小路径覆盖 hdu 3861
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 题意:输入t,表示t个样例.接下来每个样例第一行有两个数n,m表示点数和有向边的数量,接下来输入 ...
- HDU 3861.The King’s Problem 强联通分量+最小路径覆盖
The King’s Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- (匹配 最小路径覆盖)Air Raid --hdu --1151
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1151 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 3861 The King’s Problem(强连通分量+最小路径覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 题目大意: 在csdn王国里面, 国王有一个新的问题. 这里有N个城市M条单行路,为了让他的王国 ...
- HDU 3861 The King's Problem(强连通分量缩点+最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=3861 题意: 国王要对n个城市进行规划,将这些城市分成若干个城市,强连通的城市必须处于一个州,另外一个州内的任意 ...
随机推荐
- linux下安装rabbitmq 集群
1.下载erlang官网地址 http://www.erlang.org/download 挑选合适的版本 然后 wget 比如目前18.3运行命令 wget http://erlang.org/do ...
- eclipse memory analyzer对系统内存溢出堆文件解析0(转)
前言 在平时工作过程中,有时会遇到OutOfMemoryError,我们知道遇到Error一般表明程序存在着严重问题,可能是灾难性的.所以找出是什么原因造成OutOfMemoryError非常重要.现 ...
- Python学习day03 - Python基础(1)
1. 执行Python程序的两种方式 (1)交互式(Jupyter) 优点:运行一句执行一句 缺点:关闭即消失# (2)命令行式(pycharm) 优点:可以一直保存 缺点:全部写完才能调试bug虽然 ...
- <数据库>MySQL的安装及安装中存在的问题
无脑三连: 下载:https://dev.mysql.com/downloads/mysql/5.7.html#downloads 解压:任意目录 添加环境变量:WIN10步骤 我的电脑→属性→高级系 ...
- [Swoole系列入门教程 4] 定时器与心跳demo
- centos的yum配置
什么是yum ?yum,是Yellow dog Updater Modified的简称,起初是由yellow dog这一发行版的开发者Terra Soft研发,用python写成,那时还叫做yup(y ...
- agc034
A:题意:你有一个1 * n的网格,有些地方是障碍.你有两个人,分别要从a到b和从c到d,一次只能向右跳1步或者两步.求是否可行. 解:先判断有没有2个连续的障碍,然后判断是否能错车. #includ ...
- c++类成员函数的重载和覆盖有什么区别
1.成员函数被重载的特征: (1)相同的范围(在同一个类中): (2)函数名字相同: (3)参数不同: (4)virtual 关键字可有可无. 2.覆盖是指派生类函数覆盖基类函数,特征是: (1)不同 ...
- 原型模式(Prototype)(对象、克隆广告邮件)
有些对象创建过程较为复杂,而且有些时候需要频繁的创建,原型模式通过给出一个原型对象来指明所要创建的对象的类型,然后复制这个原型对象的方法创建更多同类型的对象.这就是原型模式的动机. 原型模式的主要思想 ...
- 二叉树遍历问题、时间空间复杂度、淘汰策略算法、lru数据结构、动态规划贪心算法
二叉树的前序遍历.中序遍历.后序遍历 前序遍历 遍历顺序规则为[根左右] ABCDEFGHK 中序遍历 遍历顺序规则为[左根右] BDCAEHGKF 后序遍历 遍历顺序规则为[左右根] DCBHKGF ...