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 ...
随机推荐
- go语言通道详解
https://www.ardanlabs.com/blog/2017/10/the-behavior-of-channels.html Introduction When I started to ...
- Java Number & Math 类
// java.lang.Math 常用 // xxxValue() 方法用于将 Number 对象转换为 xxx 数据类型的值并返回. System.out.println(((Integer) 5 ...
- [bzoj3524][Couriers]
题目链接 思路 观察这个\((r - l + 1)/2\),很容易证明,如果一个数出现次数大于\((r - l + 1) / 2\),那么这个区间内第\((r - l + 1) / 2 + 1\)大一 ...
- 2.Linux基础命令
linux内一切皆文件,没有文件夹只有目录,目录也是一种文件 1.一些常用按键: 将鼠标的光标从虚拟机里切换回来:Ctrl+Alt 拖动Ubuntu内的对话框:Alt键+鼠标左键拖动 清屏:Ctrl+ ...
- SpringCloud-初识
说道SpringCloud,原来就去了解过,也有很大兴趣,只是当初不知道这是个什么东西.在它之前,我学习Spring,在官网肆无忌惮的逛的时候,发现了SpringBoot,那个时候就打算开始学习Spr ...
- linux下静态库和动态库的制作
一.静态库 1.编写.c文件,在其中实现函数源代码,同时制作头文件 2.将.c文件转为.o文件 gcc -c xxx.c -o xxx.o 3.将*.o转换成库文件 a ...
- 使用perconna xtrabackup备份脚本
使用percona xtrabackup对两个数据库实例进行备份,备份的脚本如下所示: #!/bin/bash BASEDIR="/usr/local/mysql" BIN=&qu ...
- emacs简易配置
(setq-default inhibit-startup-message t tab-width 4 c-basic-offset 4 indent-tabs-mode t) (tool-bar-m ...
- vue(基础一)_基本指令的使用
一.前言 1.基本骨架 2.插值表达式{{ }} 3.vue起的作用,在开发中充当的角色MVC ...
- nginx安装配置: configure命令
configure命令用来配置nginx编译环境. 该命令定义了系统各方面功能,包括允许nginx使用的连接处理方式. 其执行结果是生成一个Makefile文件. configure命令支持如下参数: ...