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

时间:2022-09-30 17:23:48

题意:

找出不能相互访问的点集的集合的元素数量。

思路:

偏序集最长反链裸题。

代码:

#include<iostream>
#include<cstring>
using namespace std; const int maxn=;
int g[maxn][maxn]; int uN,vN;
int linker[maxn];
bool used[maxn];
bool dfs(int u)
{
for(int v = ; v < vN; v++)
if(g[u][v] && !used[v])
{
used[v] = true;
if(linker[v] == - || dfs(linker[v]))
{
linker[v] = u;
return true;
}
}
return false;
}
int hungary()
{
int res = ;
memset(linker,-,sizeof(linker));
for(int u = ; u < uN; u++)
{
memset(used,false,sizeof(used));
if(dfs(u))res++;
}
return res;
} int main()
{
int n,m,t;
cin>>t;
while (t--)
{
cin>>n>>m;
memset(g,,sizeof(g));
for (int i=; i<=m; i++)
{
int u,v;
cin>>u>>v;
g[u-][v-]=;
}
for (int k=; k<n; k++)
for (int i=; i<n; i++)
for (int j=; j<n; j++)
if (g[i][k] && g[k][j]) g[i][j]=;
uN=vN=n;
cout<<n-hungary()<<endl;
}
return ;
}

2017ICPC南宁 M题 The Maximum Unreachable Node Set【二分图】的更多相关文章

  1. The Maximum Unreachable Node Set

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

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

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

  3. The Maximum Unreachable Node Set 【17南宁区域赛】 【二分匹配】

    题目链接 https://nanti.jisuanke.com/t/19979 题意 给出n个点 m 条边 求选出最大的点数使得这个点集之间 任意两点不可达 题目中给的边是有向边 思路 这道题 实际上 ...

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

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

  5. 2017ICPC南宁补题

    https://www.cnblogs.com/2462478392Lee/p/11650548.html https://www.cnblogs.com/2462478392Lee/p/116501 ...

  6. 欧拉工程第67题:Maximum path sum II

    By starting at the top of the triangle below and moving to adjacent numbers on the row below, the ma ...

  7. LeetCode算法题-Third Maximum Number(Java实现-四种解法)

    这是悦乐书的第222次更新,第235篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第89题(顺位题号是414).给定非空的整数数组,返回此数组中的第三个最大数字.如果不存 ...

  8. 【LeetCode每天一题】Remove Nth Node From End of List&lpar;移除链表倒数第N个节点&rpar;

    Given a linked list, remove the n-th node from the end of list and return its head. Example:        ...

  9. 2017ICPC南宁赛区网络赛 Minimum Distance in a Star Graph (bfs)

    In this problem, we will define a graph called star graph, and the question is to find the minimum d ...

随机推荐

  1. wpf的UserControl用户控件怎么添加到Window窗体中

    转载自 http://www.cnblogs.com/shuang121/archive/2013/01/09/2853591.html 我们来新建一个用户控件UserControl1.xaml &l ...

  2. 【Android学习】android布局中几个距离单位的区别:px、dp、sp

    一.px 像素,我们经常说的400*800这种的就是像素,这个比较好理解. 二.dp 要理解dp,首先要先引入dpi这个概念,dpi全称是dots per inch,对角线每英寸的像素点的个数,所以, ...

  3. POJ 1458 1159

    http://poj.org/problem?id=1458 一道容易的DP,求最长公共子序列的 dp[i][j],代表str1中的第i个字母和str2中的第j个字母的最多的公共字母数 #includ ...

  4. MVC Ajax 提交是防止SCRF攻击

    //在View中 <script type="text/javascript"> @functions{ public string ToKenHeaderValue( ...

  5. ObsoleteAttribute 可适用于除程序集、模块、参数或返回值以外的所有程序元素。 将元素标记为过时可以通知用户:该元素在产品的未来版本中将被移除。

    官方文档:https://msdn.microsoft.com/zh-cn/library/system.obsoleteattribute(v=vs.110).aspx 备注 ObsoleteAtt ...

  6. LeetCode OJ 61&period; Rotate List

    Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...

  7. 好吧,CSS3 3D transform变换,不过如此!——张鑫旭

    一.写在前面的秋裤 早在去年的去年,我就大肆介绍了2D transform相关内容.看过海贼王的都知道,带D的家伙都不是好惹的,2D我辈尚可以应付,3D的话,呵呵,估计我等早就在千里之外被其霸气震晕了 ...

  8. prometheus相关文章

    prometheus book https://yunlzheng.gitbook.io/prometheus-book/ 开发自己的分布式监控Prometheus Exporter时遇到的坑 htt ...

  9. SQL Server 与MySQL中排序规则与字符集相关知识的一点总结

    字符集&&排序规则 字符集是针对不同语言的字符编码的集合,比如UTF-8字符集,GBK字符集,GB2312字符集等等,不同的字符集使用不同的规则给字符进行编码排序规则则是在特定字符集的 ...

  10. Oracle中,如何将String插入到BLOB类型字段

    1,String插入到BLOB类型字段,(这里的字符串以生成的XML为例): String XML = document.asXML();  //使用dom4j写成的xml是String类型,记得st ...