2017ICPC南宁 M题 The Maximum Unreachable Node Set【二分图】
题意:
找出不能相互访问的点集的集合的元素数量。
思路:
偏序集最长反链裸题。
代码:
#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【二分图】的更多相关文章
- The Maximum Unreachable Node Set
题目描述 In this problem, we would like to talk about unreachable sets of a directed acyclic graph G = ( ...
- 2017ICPC南宁M The Maximum Unreachable Node Set (偏序集最长反链)
题意:给你一张DAG,让你选取最多的点,使得这些点之间互相不可达. 思路:此问题和最小路径可重复点覆盖等价,先在原图上跑一边传递闭包,然后把每个点拆成两个点i, i + n, 原图中的边(a, b)变 ...
- 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南宁补题
https://www.cnblogs.com/2462478392Lee/p/11650548.html https://www.cnblogs.com/2462478392Lee/p/116501 ...
- 欧拉工程第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 ...
- LeetCode算法题-Third Maximum Number(Java实现-四种解法)
这是悦乐书的第222次更新,第235篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第89题(顺位题号是414).给定非空的整数数组,返回此数组中的第三个最大数字.如果不存 ...
- 【LeetCode每天一题】Remove Nth Node From End of List(移除链表倒数第N个节点)
Given a linked list, remove the n-th node from the end of list and return its head. Example: ...
- 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 ...
随机推荐
- Git多个SSH KEYS解决方案(含windows自动化、TortoiseGit、SourceTree等)
工作过程中,经常会使用到多个git仓库,每个git仓库对应一个账号,可以理解为每个git仓库对应一个ssh key,因此我们需要管理多个ssh key. 一.快速创建ssh key 1. 创建 ...
- Ubuntu下搜狗输入法无法输入中文
现象:无法打出中文,但是有输入框.如下图所示情形: 解决方法 删除配置文件,重启fcitx 配置文件在~/.config下的3个文件夹里SogouPY.SogouPY.users.sogou-qimp ...
- A1014. Waiting in Line
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
- Vue+koa2开发一款全栈小程序(3.vue入门、Mpvue入门)
1.Vue-cli 1.新建一个vue项目 打开cmd 官方命令行工具 npm install -g vue-cli //安装脚手架 cd到你想要存放demo的目录下,然后 vue init webp ...
- 第九篇-新建文件夹和文本文件mkdirs,createNewFile
一.新建一个empty activity的项目 二.修改AndroidMainfest.xml,添加用户权限. <?xml version="1.0" encoding=&q ...
- 第二十九节,目标检测算法之R-CNN算法详解
Girshick, Ross, et al. “Rich feature hierarchies for accurate object detection and semantic segmenta ...
- C 线程学习记录
"互斥锁"(Mutual exclusion,缩写 Mutex),防止多个线程同时读写某一块内存区域. 这时的解决方法,就是在门口挂n把钥匙.进去的人就取一把钥匙,出来时再把钥匙挂 ...
- Solr7.1--- 高亮查询
由于测试数据比较少,昨天用Java爬了简书的几百篇文章,唉,又特么两点多睡的.如果你需要这些测试文件GitHub. 如果你看过我前面的文章,直接打开db-data-config.xml文件,添加一个e ...
- C语言进阶--Day2
今天主要讲解的是函数的压栈与出栈 1. 要实现一个数组的逆置,用栈的压栈出栈观点: reverseArr(int *parr,int i,int len) { if(i != len-1) rever ...
- 2018.11.26 QLU新生赛部分题解
问题 L: 寄蒜几盒? 题目描述 现在有一个圆圈,圆圈上有若干个点,请判断能否在若干个点中选择三个点两两相连组成一个等边三角形? 这若干个点在圆圈上按顺时针顺序分布. 如果可以的话输出"Ye ...