The Maximum Unreachable Node Set
题目描述
A node set denoted by V UR ⊂ V containing several nodes is known as an unreachable node set of G if, for each two different nodes u and v in V UR , there is no way to start at u and follow a consistently-directed sequence of edges in E that finally archives the node v. You are asked in this problem to calculate the size of the maximum unreachable node set of a given graph G.
输入
For each case, the first line contains two integers n (1 ≤ n ≤ 100) and m (0 ≤ m ≤ n(n − 1)/2) indicating the number of nodes and the number of edges in the graph G. Each of the following m lines describes a directed edge with two integers u and v (1 ≤ u, v ≤ n and u 6= v) indicating an edge from the u-th node to the v-th node. All edges provided in this case are distinct.
We guarantee that all directed graphs given in input are DAGs and the sum of m in input is smaller than 500000.
输出
样例输入
3
4 4
1 2
1 3
2 4
3 4
4 3
1 2
2 3
3 4
6 5
1 2
4 2
6 2
2 3
2 5
样例输出
2
1
3 题解:先求出来传递闭包,并拆点,用二分图求原图的最小路径覆盖。
#include <bits/stdc++.h>
using namespace std;
const int N=;
bool graph[N][N],visited[N];
int n,match[N];
bool djk(int u)
{
if(visited[u]) return false;
visited[u]=true;
for(int v=;v<n;v++){
if(graph[u][v]&&(match[v]==-||djk(match[v]))){
match[v]=u;
return true;
}
}
return false;
}
int main(){
ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--){
int m;
cin>>n>>m;
memset(graph,,sizeof(graph));
for(int i=;i<m;i++){
int a,b;
cin>>a>>b;
graph[a-][b-]=true;
}
for(int k=;k<n;k++){
for(int i=;i<n;i++){
for(int j=;j<n;j++){
graph[i][j] |=graph[i][k]&&graph[k][j];
}
}
}
int result=n;
memset(match,-,sizeof(match));
memset(visited,,sizeof(visited));
for(int i=;i<n;i++){
if(djk(i)){
result--;
memset(visited,,sizeof(visited));
}
}
cout<<result<<endl;
}
}
二分图:
二分图的性质
二分图中,点覆盖数是匹配数。
    (1) 二分图的最大匹配数等于最小覆盖数,即求最少的点使得每条边都至少和其中的一个点相关联,很显然直接取最大匹配的一段节点即可。
    (2) 二分图的独立数等于顶点数减去最大匹配数,很显然的把最大匹配两端的点都从顶点集中去掉这个时候剩余的点是独立集,这是|V|-2*|M|,同时必然可以从每条匹配边的两端取一个点加入独立集并且保持其独立集性质。
    (3) DAG的最小路径覆盖,将每个点拆点后作最大匹配,结果为n-m,求具体路径的时候顺着匹配边走就可以,匹配边i→j',j→k',k→l'....构成一条有向路径。
(4)最大匹配数=左边匹配点+右边未匹配点。因为在最大匹配集中的任意一条边,如果他的左边没标记,右边被标记了,那么我们就可找到一条新的增广路,所以每一条边都至少被一个点覆盖。
(5)最小边覆盖=图中点的个数-最大匹配数=最大独立集。
二分图的判定
二分图是这样一个图: 有两顶点集且图中每条边的的两个顶点分别位于两个顶点集中,每个顶点集中没有边直接相连接!
无向图G为二分图的充分必要条件是,G至少有两个顶点,且其所有回路的长度均为偶数。
判断二分图的常见方法是染色法: 开始对任意一未染色的顶点染色,之后判断其相邻的顶点中,若未染色则将其染上和相邻顶点不同的颜色, 若已经染色且颜色和相邻顶点的颜色相同则说明不是二分图,若颜色不同则继续判断,bfs和dfs可以搞定!
易知:任何无回路的的图均是二分图。
参考:http://dsqiu.iteye.com/blog/1689505
模板:
The Maximum Unreachable Node Set的更多相关文章
- 2017ICPC南宁 M题 The Maximum Unreachable Node Set【二分图】
		题意: 找出不能相互访问的点集的集合的元素数量. 思路: 偏序集最长反链裸题. 代码: #include<iostream> #include<cstring> using n ... 
- The Maximum Unreachable Node Set 【17南宁区域赛】 【二分匹配】
		题目链接 https://nanti.jisuanke.com/t/19979 题意 给出n个点 m 条边 求选出最大的点数使得这个点集之间 任意两点不可达 题目中给的边是有向边 思路 这道题 实际上 ... 
- ACM-ICPC 2017 南宁赛区现场赛 M. The Maximum Unreachable Node Set(二分图)
		题目链接:https://nanti.jisuanke.com/t/19979 题意:给出一个 n 个点,m 条边的 DAG,选出最大的子集使得其中结点两两不能到达. 题解:参考自:https://b ... 
- 2017ICPC南宁M The Maximum Unreachable Node Set (偏序集最长反链)
		题意:给你一张DAG,让你选取最多的点,使得这些点之间互相不可达. 思路:此问题和最小路径可重复点覆盖等价,先在原图上跑一边传递闭包,然后把每个点拆成两个点i, i + n, 原图中的边(a, b)变 ... 
- f2fs源码解析(五) node管理结构梳理
		node是f2fs重要的管理结构, 它非常重要! 系统挂载完毕后, 会有一个f2fs_nm_info结构的node管理器来管理node的分配. f2fs_nm_info中最让人疑惑的是几颗基数树: s ... 
- oracle 11g crs检测结果
		+ASM1@testdb11a /oracle/media/grid$ ./runcluvfy.sh stage -pre crsinst -n testdb11a,testdb11b -verbos ... 
- runcluvfy.sh运行结果
		$ ./runcluvfy.sh stage -pre crsinst -n rac11g1,rac11g2 -verbose Performing pre-checks for cluster se ... 
- oracle11g RAC添加节点
		OS: [root@rac ~]# more /etc/oracle-releaseOracle Linux Server release 5.7 DB: SQL> SELECT * FROM ... 
- Oracle11.2.0.4 RAC安装文档
		1 环境配置 参考官方文档<Grid Infrastructure Installation Guide for Linux> 1.1 软件环境 操作系统: [root@howe1 ~]# ... 
随机推荐
- 实用的VMware虚拟机使用技巧十一例
			同时安装多个操作系统的方法有很多,例如Linux Grub引导.WindowsNT OS Loader引导.System Commander引导.Partition Magic改变激活分区等,但总是比 ... 
- pinpoint 单机HBASE数据量过大问题解决
			Pinpoint接入业务监控后数据量大涨,平均每周Hbase数据增量35G左右,数据量太大,需要对数据进行定期清理,否则监控可用性降低. 操作步骤 查找出数据大的hbase表 [root@iZ28ov ... 
- VUE- 引用视频组件
			VUE- 引用视频组件 安装依赖 cnpm install vue-video-player -S cnpm install video.js -S 全局引用: 在main.js中 import Vu ... 
- re模块2
			# 元字符+,*遇到?后就会变为贪婪匹配 print(re.findall('abc+?','abcccccc')) #['abc'] print(re.findall('abc*?','abcccc ... 
- Eclipse 配置spring boot pom.xml第1行报错的两种解决办法
			现象 通过spring boot项目导入eclipse后,pom.xml文件的第一行总是报错.这里使用的spring版本是2.1.5,2.1.4以前的版本等其他版本的spring没有这个问题. 解决办 ... 
- 特斯拉私有化VS蔚来上市,电动汽车站在十字路口上
			当下,对于电动汽车来说既是一个最好的时代,也是一个最坏的时代.好的一面是业界.投资者.消费者对电动汽车的关注度愈来愈高,坏的一面则是电动汽车正处于一个非常尴尬的处境.从大环境来看,电动汽车自身的产品力 ... 
- Anaconda 添加清华源与恢复默认源
			1.添加清华源 查看清华大学官方镜像源文档:https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/ 本文基于Windows平台,首先用命令: conda ... 
- POJ - 1061 扩展欧几里德算法+求最小正整数解
			//#pragma comment(linker, "/STACK:1024000000,1024000000") //#pragma GCC optimize(2) #inclu ... 
- 面向对象  part5
			构造函数模式与原型模式结合 function Person(name) = { this.name = name this.friends = ["a", "b" ... 
- ZJNU 2135 - 小智的宝可梦
			因为成环 所以可以枚举第1只与第n只喂的次数 然后第1只和第2只的次数就固定了,以此类推,则所有宝可梦喂的次数都固定了 最后处理完检查是否全为0,不是则进行下一次枚举,是则直接输出Yes 如果所有枚举 ... 
