题目链接

https://nanti.jisuanke.com/t/19979

题意

给出n个点 m 条边 求选出最大的点数使得这个点集之间 任意两点不可达 题目中给的边是有向边

思路

这道题 实际上是求 二分图的最大独立集

二分图的最大独立集 = 顶点数 - 二分图最大匹配

相关概念:

https://blog.csdn.net/whosemario/article/details/8513836

那操作就是

先Flyod 跑出 可达矩阵 再二分匹配

答案就是 n - res

AC代码

  1. #pragma comment(linker, "/STACK:102400000,102400000")
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <ctype.h>
  5. #include <cstdlib>
  6. #include <cmath>
  7. #include <climits>
  8. #include <ctime>
  9. #include <iostream>
  10. #include <algorithm>
  11. #include <deque>
  12. #include <vector>
  13. #include <queue>
  14. #include <string>
  15. #include <map>
  16. #include <stack>
  17. #include <set>
  18. #include <list>
  19. #include <numeric>
  20. #include <sstream>
  21. #include <iomanip>
  22. #include <limits>
  23. #define pb push_back
  24. #define fi first
  25. #define se second
  26. #define L(on) ((on)<<1)
  27. #define R(on) (L(on) | 1)
  28. #define mkp(a, b) make_pair(a, b)
  29. #define bug puts("***bug***");
  30. #define all(x) x.begin(), x.end()
  31. #define rall(x) x.rbegin(), x.rend()
  32. #define CLR(a, b) memset(a, (b), sizeof(a));
  33. #define syn_close ios::sync_with_stdio(false); cin.tie(0);
  34. #define sp system("pause");
  35. //#define gets gets_s
  36. using namespace std;
  37. typedef long long ll;
  38. typedef long double ld;
  39. typedef long double ld;
  40. typedef unsigned long long ull;
  41. typedef pair <int, int> pii;
  42. typedef pair <double, double> pdd;
  43. typedef pair <ll, ll> pll;
  44. typedef vector <int> vi;
  45. typedef vector <ll> vll;
  46. typedef vector < vi > vvi;
  47. const double PI = acos(-1.0);
  48. const double EI = exp(1.0);
  49. const double eps = 1e-8;
  50. inline int read()
  51. {
  52. char c = getchar(); int ans = 0, vis = 1;
  53. while (c < '0' || c > '9') { if (c == '-') vis = -vis; c = getchar(); }
  54. while (c >= '0' && c <= '9') { ans = ans * 10 + c - '0'; c = getchar(); }
  55. return ans * vis;
  56. }
  57. const int INF = 0x3f3f3f3f;
  58. const ll INFLL = 0x3f3f3f3f3f3f3f3fll;
  59. const int maxn = (int)1e2 + 10;
  60. const int MAXN = (int)1e4 + 10;
  61. const ll MOD = (ll)1e9 + 7;
  62. int G[maxn][maxn];
  63. int n, m;
  64. void input()
  65. {
  66. n = read(), m = read();
  67. for (int i = 0; i < n; i++)
  68. for (int j = 0; j < n; j++)
  69. G[i][j] = 0;
  70. int x, y;
  71. for (int i = 0; i < m; i++)
  72. {
  73. x = read() - 1, y = read() - 1;
  74. G[x][y] = 1;
  75. }
  76. }
  77. void Floyd()
  78. {
  79. for (int k = 0; k < n; k++)
  80. for (int i = 0; i < n; i++)
  81. for (int j = 0; j < n; j++)
  82. G[i][j] = (G[i][j] || G[i][k] && G[k][j]);
  83. }
  84. int uN, vN;
  85. int linker[maxn];
  86. bool used[maxn];
  87. bool dfs(int u)
  88. {
  89. for (int v = 0; v < vN; v++)
  90. if (G[u][v] && !used[v])
  91. {
  92. used[v] = true;
  93. if (linker[v] == -1 || dfs(linker[v]))
  94. {
  95. linker[v] = u;
  96. return true;
  97. }
  98. }
  99. return false;
  100. }
  101. int hungary()
  102. {
  103. int res = 0;
  104. CLR(linker, -1);
  105. for (int u = 0; u < uN; u++)
  106. {
  107. CLR(used, false);
  108. if (dfs(u))
  109. res++;
  110. }
  111. return res;
  112. }
  113. void solve()
  114. {
  115. Floyd(); uN = vN = n;
  116. printf("%d\n", n - hungary());
  117. }
  118. int main()
  119. {
  120. int t = read();
  121. while (t--)
  122. {
  123. input(); solve();
  124. }
  125. }

The Maximum Unreachable Node Set 【17南宁区域赛】 【二分匹配】的更多相关文章

  1. 17南宁区域赛 I - Rake It In 【DFS】

    题目链接 https://nanti.jisuanke.com/t/19975 题意 Alice 和 Bob 玩游戏 在一个4x4 的方格上 每个人 每次选择2x2的区域 将里面的四个值求和加到最后的 ...

  2. 高精度乘法-17南宁区域赛F -The Chosen One

    题目大意:给你一个n,然后从1~n隔一个选一个,挑出一个集合然后从集合中继续隔一个挑一个,直到只有一个数,问最后一个数是多少?2<=n<=1050 例如n=5,先选出2,4最后选择4.n= ...

  3. 17 南宁区域赛 F - The Chosen One 【规律】

    题目链接 https://nanti.jisuanke.com/t/19972 题意 给出一个n 然后将 n 个数 标号为 1 -> n 按顺序排列 每次抽掉 奇数位的数 然后求最后剩下那个数字 ...

  4. 17南宁区域赛 J - Rearrangement 【规律】

    题目链接 https://nanti.jisuanke.com/t/19976 题意 给出 一个n 然后 给出 2*n 个数 可以重新排列成两行 然后 相邻的两个数 加起来 不能被三整除 可以上下相邻 ...

  5. The Maximum Unreachable Node Set

    题目描述 In this problem, we would like to talk about unreachable sets of a directed acyclic graph G = ( ...

  6. 2017ICPC南宁 M题 The Maximum Unreachable Node Set【二分图】

    题意: 找出不能相互访问的点集的集合的元素数量. 思路: 偏序集最长反链裸题. 代码: #include<iostream> #include<cstring> using n ...

  7. ACM-ICPC 2017 南宁赛区现场赛 M. The Maximum Unreachable Node Set(二分图)

    题目链接:https://nanti.jisuanke.com/t/19979 题意:给出一个 n 个点,m 条边的 DAG,选出最大的子集使得其中结点两两不能到达. 题解:参考自:https://b ...

  8. 2017ICPC南宁M The Maximum Unreachable Node Set (偏序集最长反链)

    题意:给你一张DAG,让你选取最多的点,使得这些点之间互相不可达. 思路:此问题和最小路径可重复点覆盖等价,先在原图上跑一边传递闭包,然后把每个点拆成两个点i, i + n, 原图中的边(a, b)变 ...

  9. 2014年亚洲区域赛北京赛区现场赛A,D,H,I,K题解(hdu5112,5115,5119,5220,5122)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 下午在HDU上打了一下今年北京区域赛的重现,过了5题,看来单挑只能拿拿铜牌,呜呜. ...

随机推荐

  1. angularjs 可以加入html标签方法------ng-bind-html的用法总结(2)

    angular-ngSanitize模块-$sanitize服务详解 本篇主要讲解angular中的$sanitize这个服务.此服务依赖于ngSanitize模块. 要学习这个服务,先要了解另一个指 ...

  2. iOS 后台定位审核被拒How to clarify the purpose of its use in the locatio

    4.5 - Apps using background location services must provide a reason that clarifies the purpose of th ...

  3. 创建oracle本地数据库步骤详解

    前提:安装好oracle数据库客户端: PL/SQL DEVELOPER 1.打开DatabaseConfiguration Assistant,如图: 选择创建数据库->next->选择 ...

  4. PHPstorm配置远程及本地服务器

    首先打开PHPStorm的设置. 找到如下页面 OPEN一个项目,路径为XAMPP的安装路径 选择Local or mounted folder 设置以上属性,upload/download proj ...

  5. Play on Words UVA - 10129 欧拉路径

    关于欧拉回路和欧拉路径 定义:欧拉回路:每条边恰好只走一次,并能回到出发点的路径欧拉路径:经过每一条边一次,但是不要求回到起始点 ①首先看欧拉回路存在性的判定: 一.无向图每个顶点的度数都是偶数,则存 ...

  6. nefu 118 n!后面有多少个0 算数基本定理,素数分解

    n!后面有多少个0 Time Limit 1000ms Memory Limit 65536K description 从输入中读取一个数n,求出n! 中末尾0的个数. input 输入有若干行.第一 ...

  7. 在linux虚机中装vmtools

    很多用户在测试linux操作系统的时候喜欢用虚拟机,因为虚拟机方便而且可以同时在一台PC机上虚拟出来不同版本的linux操作系统,但是虚拟机和物理机之间的文件传输倒成了个问题,有人说可以使用vmtoo ...

  8. Prime pair connection (Project Euler 134)

    题目大意: 对于连续的质数$p1$, $p2$, 满足$5 <= p1 <= 1000000$ 求出最小的整数$S$, 它以 $p1$结尾并且能够被$p2$整除. 求$S$的和. 思路: ...

  9. node.js 入门

    什么是Node.js?还服务器端javascript?对于这个概念我在这篇文章不做解释,可以自己去搜索了解下,服务器端js不是新技术,只是最近的node.js的火爆让他爆发了,我会在以后的文章里解释什 ...

  10. GoogleMap-------manifest文件配置

    前言:在使用GoopleMap之前需要配置manifest文件 1.这个可有可无,com.xhm.meishi是项目的包名 <!-- 声明调用这个应用需要的权限 --> <permi ...