题目描述

In this problem, we would like to talk about unreachable sets of a directed acyclic graph G = (V, E). In mathematics a directed acyclic graph (DAG) is a directed graph with no directed cycles. That is a graph such that there is no way to start at any node and follow a consistently-directed sequence of edges in E that eventually loops back to the beginning again.
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.

输入

The input contains several test cases and the first line contains an integer T (1 ≤ T ≤ 500) which is the number of test cases.
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.

输出

For each test case, output an integer in a line which is the size of the maximum unreachable node set of G.

样例输入

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=100;
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=0;v<n;v++){if(graph[u][v]&&(match[v]==-1||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,0,sizeof(graph));for(int i=0;i<m;i++){int a,b;cin>>a>>b;graph[a-1][b-1]=true;}for(int k=0;k<n;k++){for(int i=0;i<n;i++){for(int j=0;j<n;j++){graph[i][j] |=graph[i][k]&&graph[k][j];}}}int result=n;memset(match,-1,sizeof(match));memset(visited,0,sizeof(visited));for(int i=0;i<n;i++){if(djk(i)){result--;memset(visited,0,sizeof(visited));}}cout<<result<<endl;}
}

View Code

二分图:

二分图的性质

二分图中,点覆盖数是匹配数。
    (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

模板:

有向无环图(DAG)的最小路径覆盖


转载于:https://www.cnblogs.com/smallocean/p/8743013.html

The Maximum Unreachable Node Set相关推荐

  1. ICPC2017 Naning - The Maximum Unreachable Node Set

    标签: 最大独立集 最小路径覆盖 题目描述 In this problem, we would like to talk about unreachable sets of a directed ac ...

  2. 图论 —— DAG 的覆盖与独立集

    [概述] 在 DAG 的覆盖与独立集问题中,常见的问题分为三类: 最小路径点覆盖 最小路径可重复点覆盖 最大独立集数 这三类问题都可以利用二分图的匈牙利算法来解决. [最小路径覆盖] 最小路径覆盖:给 ...

  3. 为11.2.0.2 Grid Infrastructure添加节点

    在之前的文章中我介绍了为10g RAC Cluster添加节点的具体步骤.在11gr2中Oracle CRS升级为Grid Infrastructure,通过GI我们可以更方便地控制CRS资源如:VI ...

  4. golang检查tcp是否可用_宕机处理:Kubernetes集群高可用实战总结

    导语 | 在企业生产环境,Kubernetes高可用是一个必不可少的特性,其中最通用的场景就是如何在Kubernetes集群宕机一个节点的情况下保障服务依旧可用.本文对在该场景下实现集群和应用高可用过 ...

  5. Oracle11.2.0.4 RAC安装文档

    1 环境配置 参考官方文档<Grid Infrastructure Installation Guide for Linux> 1.1 软件环境 操作系统: [root@howe1 ~]# ...

  6. 12C ORA-错误汇总20

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! CLSM ...

  7. Installation Oracle11gR2 RAC on SuSE Linux Enterprise Server 11

    SLES11安装参考我的博文 Installation SUSE Linux Enterprise Server 11 vzwc1:~ # cat /etc/issueWelcome to SUSE ...

  8. 使用 VMware 16 RHEL7.7 虚拟机静默安装 Oracle 19c RAC

    作者 | JiekeXu 来源 | JiekeXu DBA之路(ID: JiekeXu_IT) 大家好,我是 JiekeXu,很高兴又和大家见面了,今天和大家一起来看看 使用 VMware 16  R ...

  9. Oracle 19C RAC 静默(silent)安装on RHEL7.x

    后续文档修订详见Github 修订记录 日期 版本 描述 作者 2018-05-09 v1.0 初稿 Yong 一.安装准备 1.1.RHEL版本及IP规划 1.1.1.OS版本信息 [root@lo ...

最新文章

  1. 关于人脸识别数据库的几点介绍
  2. python 实现感知器(一)
  3. JDBC常用API小结
  4. 程序员的职业素养文摘
  5. CCKS 2018 | 工业界论坛报告简介
  6. Linux进阶之路————用户管理
  7. 大规模研究表明,睡眠不足、压力给大脑带来的伤害,犹如脑震荡
  8. android答辩问题,我的设计是安卓微博,答辩时老师会问些什么问题
  9. python常见的控制流结构有_【Python】控制流语句、函数、模块、数据结构
  10. 如何用手机NFC代替小区门禁?
  11. Java会走向晦暗吗?Kotlin会取而代之吗
  12. docker入门2---docker的初体验
  13. mysqldump备份所有数据库,恢复单个库的场景预演
  14. 阿里面试记录-程序上机
  15. JAVA中jspinner设置选中内容_java – 如何在JSpinner中获取所选项的值?
  16. [转]在WPF中打开网页方法总结
  17. 太神了-图片可以转换成Word文档了
  18. 1人30天44587行代码,分享舍得网开发过程
  19. python通过什么对象连接数据库步骤_Python连接MySQL数据库方法介绍(超详细!手把手项目案例操作)...
  20. 笛卡尔生平及其成就介绍

热门文章

  1. 《数据驱动安全:数据安全分析、可视化和仪表盘》一2.3 数据帧介绍
  2. 我被面试官问到的问题-5
  3. 移动端web开发常见问题
  4. 专业写博一天------ArrayList 线程安全
  5. 2010年8月和9月成果
  6. [XA]转:一个关于结对编程(Pair Programming)的讲义
  7. pycharm如何修改背景成护眼色和字体大小
  8. MySQL入门系列:查询简介(四)之类型转换和分组查询
  9. jpa tutorials
  10. iOS网络 把数据存入钥匙串