题目链接

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

题意

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

思路

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

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

相关概念:

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

那操作就是

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

答案就是 n - res

AC代码

#pragma comment(linker, "/STACK:102400000,102400000")

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <list>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define pb push_back
#define fi first
#define se second
#define L(on) ((on)<<1)
#define R(on) (L(on) | 1)
#define mkp(a, b) make_pair(a, b)
#define bug puts("***bug***");
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define CLR(a, b) memset(a, (b), sizeof(a));
#define syn_close ios::sync_with_stdio(false); cin.tie(0);
#define sp system("pause");
//#define gets gets_s using namespace std; typedef long long ll;
typedef long double ld;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <double, double> pdd;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector < vi > vvi; const double PI = acos(-1.0);
const double EI = exp(1.0);
const double eps = 1e-8; inline int read()
{
char c = getchar(); int ans = 0, vis = 1;
while (c < '0' || c > '9') { if (c == '-') vis = -vis; c = getchar(); }
while (c >= '0' && c <= '9') { ans = ans * 10 + c - '0'; c = getchar(); }
return ans * vis;
} const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fll;
const int maxn = (int)1e2 + 10;
const int MAXN = (int)1e4 + 10;
const ll MOD = (ll)1e9 + 7; int G[maxn][maxn];
int n, m; void input()
{
n = read(), m = read();
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
G[i][j] = 0;
int x, y;
for (int i = 0; i < m; i++)
{
x = read() - 1, y = read() - 1;
G[x][y] = 1;
}
} void Floyd()
{
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
G[i][j] = (G[i][j] || G[i][k] && G[k][j]);
} int uN, vN;
int linker[maxn];
bool used[maxn]; bool dfs(int u)
{
for (int v = 0; v < vN; v++)
if (G[u][v] && !used[v])
{
used[v] = true;
if (linker[v] == -1 || dfs(linker[v]))
{
linker[v] = u;
return true;
}
}
return false;
} int hungary()
{
int res = 0;
CLR(linker, -1);
for (int u = 0; u < uN; u++)
{
CLR(used, false);
if (dfs(u))
res++;
}
return res;
} void solve()
{
Floyd(); uN = vN = n;
printf("%d\n", n - hungary());
} int main()
{
int t = read();
while (t--)
{
input(); solve();
}
}

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. 前端js文件添加版本号

    客户端会缓存这些css或js文件,因此每次升级了js或css文件后,改变版本号,客户端浏览器就会重新下载新的js或css文件 ,刷性缓存的作用.大家可能有时候发现修改了样式或者js,刷新的时候不变,就 ...

  2. abp 列表和明细页面的规则说明

    0>列表区域mainviewbody 1>列表头mainviewheader 名称 2>列表条件mainviewcodtionbody 条件区 3>列表工具栏mainviewt ...

  3. sublime和webstorm安装zencoding

    [webstorm] 1.下载模板,地址为http://code.google.com/p/zen-coding/downloads/list,下载以下文件 WebIDE and IntelliJ I ...

  4. flex初始化方法

    initalize是初始化,creationcomplete是创建完成,applicationComplete是应用程序中所有的实例都创建完成后才执行,三者的执行顺序是intalize creatio ...

  5. 把world转成html

    本来用php转的 效果不太理想 很不稳定 最后试了下java 效果不错 只记录java的方法好了 其实他们的原理都是一样的啊,都是用到了微软的com 首先是准备工作 下载(明确dll的版本是64位的还 ...

  6. 安装VC6.0遇到的问题

    1. 问题现象 安装VC6.0后,又安装了VS2005.用VC6.0打开以前的.dsw文件时,程序自动关闭.如下图所示. 具体操作是:选择一个.dsw文件,右键菜单[打开方式]中选择[Microsof ...

  7. 理解和使用WPF 验证机制(值得推荐)

    首先建立一个demo用以学习和实验WPF Data Validation机制.创建一个数据实体类: public class Employee { public string Name { get;  ...

  8. BAPI、badi 和 LSMW 的相同点和不同点及具体操作

    一开始badi.BAPI.LSMW关系极其混乱,好像都是传输数据, just transfer data from SAP system to non-SAP system or transfer d ...

  9. Python 对Twitter tweet的元素 (Word, Screen Name, Hash Tag)的频率分析

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-2 @author: guaguastd @name: tw ...

  10. 第一篇:尽量多的以 const/enum/inline 替代 #define

    前言 在面向过程语言,如 C 语言中,#define 非常常见,也确实好用,值得提倡.但在如今面向对象的语言,如 C++ 语言中,#define 就要尽量少用了. 为何在 C++ 中就要少用了呢? 这 ...