Girls and Boys

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6942    Accepted Submission(s): 3118

Problem Description
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.

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 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
Accepted Code:
 /*************************************************************************
> 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 最小路径覆盖的更多相关文章

  1. hdu 1151 最小路径覆盖

    先说说最小路径覆盖的定义 定义:在一个有向图中,找出最少的路径,使得这些路径,经过每一个点,且每一个点只与一条路径相关联, 由上面得出: 1.一个单独的点是一个路径 2:如果有路径a,b,c....f ...

  2. hdu 1151 Air Raid(二分图最小路径覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS   Memory Limit: 10000K To ...

  3. HDU 6311 Cover (无向图最小路径覆盖)

    HDU 6311 Cover (无向图最小路径覆盖) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...

  4. HDU 3861 The King’s Problem 最小路径覆盖(强连通分量缩点+二分图最大匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 最小路径覆盖的一篇博客:https://blog.csdn.net/qq_39627843/ar ...

  5. 缩点+最小路径覆盖 hdu 3861

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 题意:输入t,表示t个样例.接下来每个样例第一行有两个数n,m表示点数和有向边的数量,接下来输入 ...

  6. HDU 3861.The King’s Problem 强联通分量+最小路径覆盖

    The King’s Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. (匹配 最小路径覆盖)Air Raid --hdu --1151

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1151 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  8. HDU 3861 The King’s Problem(强连通分量+最小路径覆盖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 题目大意: 在csdn王国里面, 国王有一个新的问题. 这里有N个城市M条单行路,为了让他的王国 ...

  9. HDU 3861 The King's Problem(强连通分量缩点+最小路径覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=3861 题意: 国王要对n个城市进行规划,将这些城市分成若干个城市,强连通的城市必须处于一个州,另外一个州内的任意 ...

随机推荐

  1. 定时ping取返回值并绘图

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  2. 【neo4j】neo4j Desktop1.1.9,windows 安装

    一.neo4j 介绍 Neo4j是一个高性能的,NOSQL图形数据库,它将结构化数据存储在网络上而不是表中.它是一个嵌入式的.基于磁盘的.具备完全的事务特性的Java持久化引擎,但是它将结构化数据存储 ...

  3. js 实现横向滚动轮播并中间暂停下

    效果: html: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...

  4. 第一个简单netty程序

    一个简单的netty的程序,主要是netty的客户端和服务端通信. 大部分说明都写在代码注释中 netty server TimeServer import io.netty.bootstrap.Se ...

  5. 数据挖掘-diabetes数据集分析-糖尿病病情预测_线性回归_最小平方回归

    # coding: utf-8 # 利用 diabetes数据集来学习线性回归 # diabetes 是一个关于糖尿病的数据集, 该数据集包括442个病人的生理数据及一年以后的病情发展情况. # 数据 ...

  6. C开发系列-continue与break

    break break使用场景 switch语句:退出整个switch语句 循环结构:退出整个循环语句 while循环 do while循环 for 循环 continue continue使用场景 ...

  7. 2019-2-18-VisualStudio-给项目添加特殊的-Nuget-的链接

    title author date CreateTime categories VisualStudio 给项目添加特殊的 Nuget 的链接 lindexi 2019-02-18 15:56:48 ...

  8. ROS 日志消息(C++)

    1.日志级别 日志消息分为五个不同的严重级别宏,与Android的Log定义的严重级别类似,如下基础宏: ROS_DEBUG_STREAM.ROS_INFO_STREAM.ROS_WARN_STREA ...

  9. Django项目:CRM(客户关系管理系统)--57--47PerfectCRM实现CRM客户报名流程02

    图片另存为  16*16  名字修改为      bpm_logo.jpg /*! *bootstrap.js * * Bootstrap v3.3.7 (http://getbootstrap.co ...

  10. sql错误;The user specified as a definer ('tester'@'%') does not exist

    在复制和导数据库时提示错误:SELECT command denied to user 'tester'@'%' for column 'uID' in table 'view_enterprise_ ...