bzoj3546[ONTAK2010]Life of the Party
题意是裸的二分图关键点(必然在二分图最大匹配中出现的点).比较经典的做法在cyb15年的论文里有:

前几天写jzoj5007的时候脑补了一种基于最小割可行边的做法:考虑用最大流求解二分图匹配.如果某个点必须在最大匹配中出现,相当于删去这个点后最大匹配数目减少,即删去这个点和源/汇点的连边后剩下的网络中s到t的最小割减小.反之,如果删去这个点后最大匹配数目不变,那么删去这个点和源/汇的连边后网络的最小割不变.上述两个条件分别等价于是否存在一个原网络的最小割方案包含这个点和源/汇的连边,于是转化成网络流中的最小割可行边问题,可以通过在残量网络上用tarjan求SCC解决,即将残量网络上所有流量不为零的正向边和反向边取出,按照边原先的指向建图,求SCC,如果某条满流边连接的两个点在不同的强联通分量中说明这条边是最小割的可行边.这个做法写起来比较麻烦,不是很优越.
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=,maxm=;
struct edge{
int to,next,w;
}lst[maxm],lst2[maxm];int len=,first[maxn],_first[maxn],first2[maxn],len2=;
void addedge(int a,int b,int w){
lst[len].to=b;lst[len].next=first[a];lst[len].w=w;first[a]=len++;
lst[len].to=a;lst[len].next=first[b];lst[len].w=;first[b]=len++;
}
void addedge2(int a,int b){
lst2[len2].to=b;lst2[len2].next=first2[a];first2[a]=len2++;
// lst2[len2].to=a;lst2[len2].next=first2[b];lst2[len2].w=w;first2[b]=len2++;
}
int n1,n2,m;
int q[maxn],vis[maxn],dis[maxn],s,t,head,tail,T;
bool bfs(){
head=tail=;vis[s]=++T;dis[s]=;q[tail++]=s;
while(head!=tail){
int x=q[head++];
for(int pt=first[x];pt!=-;pt=lst[pt].next){
if(lst[pt].w&&vis[lst[pt].to]!=T){
dis[lst[pt].to]=dis[x]+;vis[lst[pt].to]=T;q[tail++]=lst[pt].to;
}
}
}
if(vis[t]==T)memcpy(_first,first,sizeof(first));
return vis[t]==T;
}
int dfs(int x,int lim){
if(x==t)return lim;
int flow=,a;
for(int pt=_first[x];pt!=-;pt=lst[pt].next){
_first[x]=pt;
if(lst[pt].w&&dis[lst[pt].to]==dis[x]+&&(a=dfs(lst[pt].to,min(lst[pt].w,lim-flow)))){
lst[pt].w-=a;lst[pt^].w+=a;flow+=a;
if(lim==flow)return flow;
}
}
return flow;
}
int dinic(){
int ans=,x;
while(bfs())while(x=dfs(s,0x7f7f7f7f))ans+=x;
return ans;
}
int used[maxn];
int ans1[maxn],ans2[maxn];
int dfn[maxn],clk;
void Dfs(int x,int typ){
dfn[x]=clk;
for(int pt=first[x];pt!=-;pt=lst[pt].next){
if(lst[pt].w==typ&&dfn[lst[pt].to]!=clk)Dfs(lst[pt].to,typ);
}
}
int main(){
memset(first,-,sizeof(first));
scanf("%d%d%d",&n1,&n2,&m);
int a,b;
s=;t=n1+n2+;
for(int i=;i<=n1;++i)addedge(s,i,);
for(int i=;i<=n2;++i)addedge(n1+i,t,);
for(int i=;i<=m;++i){
scanf("%d%d",&a,&b);addedge(a,n1+b,);
}
dinic();
for(int pt=first[s];pt!=-;pt=lst[pt].next){
if(lst[pt].w==)used[lst[pt].to]=;
}
for(int pt=first[t];pt!=-;pt=lst[pt].next){
if(lst[pt].w==)used[lst[pt].to]=;
}
++clk;
for(int i=;i<=n1;++i){
if(!used[i])Dfs(i,);
}
for(int i=;i<=n1;++i){
if(used[i]&&dfn[i]!=clk)ans1[i]=;
}
++clk;
for(int i=;i<=n2;++i){
if(!used[n1+i])Dfs(n1+i,);
}
for(int i=n1+;i<=n1+n2;++i){
if(used[i]&&dfn[i]!=clk)ans2[i]=;
}
for(int i=;i<=n1;++i)if(ans1[i])printf("%d\n",i);
for(int i=;i<=n2;++i)if(ans2[i+n1])printf("%d\n",i);
return ;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=,maxm=;
struct edge{
int to,next,w;
}lst[maxm],lst2[maxm];int len=,first[maxn],_first[maxn],first2[maxn],len2=;
void addedge(int a,int b,int w){
lst[len].to=b;lst[len].next=first[a];lst[len].w=w;first[a]=len++;
lst[len].to=a;lst[len].next=first[b];lst[len].w=;first[b]=len++;
}
void addedge2(int a,int b){
lst2[len2].to=b;lst2[len2].next=first2[a];first2[a]=len2++;
// lst2[len2].to=a;lst2[len2].next=first2[b];lst2[len2].w=w;first2[b]=len2++;
}
int n1,n2,m;
int q[maxn],vis[maxn],dis[maxn],s,t,head,tail,T;
bool bfs(){
head=tail=;vis[s]=++T;dis[s]=;q[tail++]=s;
while(head!=tail){
int x=q[head++];
for(int pt=first[x];pt!=-;pt=lst[pt].next){
if(lst[pt].w&&vis[lst[pt].to]!=T){
dis[lst[pt].to]=dis[x]+;vis[lst[pt].to]=T;q[tail++]=lst[pt].to;
}
}
}
if(vis[t]==T)memcpy(_first,first,sizeof(first));
return vis[t]==T;
}
int dfs(int x,int lim){
if(x==t)return lim;
int flow=,a;
for(int pt=_first[x];pt!=-;pt=lst[pt].next){
_first[x]=pt;
if(lst[pt].w&&dis[lst[pt].to]==dis[x]+&&(a=dfs(lst[pt].to,min(lst[pt].w,lim-flow)))){
lst[pt].w-=a;lst[pt^].w+=a;flow+=a;
if(lim==flow)return flow;
}
}
return flow;
}
int dinic(){
int ans=,x;
while(bfs())while(x=dfs(s,0x7f7f7f7f))ans+=x;
return ans;
}
int ans1[maxn],ans2[maxn];
namespace Tarjan{
int stack[maxn],top,dfn[maxn],low[maxn],T,belong[maxn],tot;
bool ins[maxn];
void dfs(int x){
low[x]=dfn[x]=++T;ins[x]=true;stack[top++]=x;
for(int pt=first2[x];pt;pt=lst2[pt].next){
if(!dfn[lst2[pt].to]){
dfs(lst2[pt].to);
if(low[lst2[pt].to]<low[x])low[x]=low[lst2[pt].to];
}else if(ins[lst2[pt].to]&&dfn[lst2[pt].to]<low[x])low[x]=dfn[lst2[pt].to];
}
if(dfn[x]==low[x]){
++tot;
do{
ins[stack[--top]]=false;
belong[stack[top]]=tot;
}while(stack[top]!=x);
}
}
void tarjan(){
for(int i=s;i<=t;++i){
if(!dfn[i])dfs(i);
}
}
};
int main(){
memset(first,-,sizeof(first));
scanf("%d%d%d",&n1,&n2,&m);
int a,b;
s=;t=n1+n2+;
for(int i=;i<=n1;++i)addedge(s,i,);
for(int i=;i<=n2;++i)addedge(n1+i,t,);
for(int i=;i<=m;++i){
scanf("%d%d",&a,&b);addedge(a,n1+b,);
}
dinic();
for(int i=s;i<=t;++i){
for(int pt=first[i];pt!=-;pt=lst[pt].next){
if(lst[pt].w){
if(lst[pt^].w)addedge2(i,lst[pt].to);
else addedge2(i,lst[pt].to);
}
}
}
Tarjan::tarjan();
using Tarjan::belong;
for(int i=s;i<=t;++i){
for(int pt=first[i];pt!=-;pt=lst[pt].next){
if(lst[pt].w==&&belong[i]!=belong[lst[pt].to]){
if(i==s&&lst[pt].to<=n1){
ans1[lst[pt].to]=;
}
if(lst[pt].to==t&&i>n1){
ans2[i-n1]=;
}
}
}
}
for(int i=;i<=n1;++i)if(ans1[i])printf("%d\n",i);
for(int i=;i<=n2;++i)if(ans2[i])printf("%d\n",i);
return ;
}
bzoj3546[ONTAK2010]Life of the Party的更多相关文章
- 【BZOJ】【3550】【ONTAK2010】Vacation
网络流/费用流 Orz太神犇了这题…… 我一开始想成跟Intervals那题一样了……每个数a[i]相当于覆盖了(a[i]-n,a[i]+n)这个区间……但是这样是错的!!随便就找出反例了……我居然还 ...
- BZOJ3550: [ONTAK2010]Vacation
3550: [ONTAK2010]Vacation Time Limit: 10 Sec Memory Limit: 96 MBSubmit: 91 Solved: 71[Submit][Stat ...
- bzoj 3545&&3551: [ONTAK2010]Peaks &&加强版 平衡树&&并查集合并树&&主席树
3545: [ONTAK2010]Peaks Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 635 Solved: 177[Submit][Stat ...
- BZOJ 3544: [ONTAK2010]Creative Accounting( BST )
题意 : 一段序列 , 求一段子序列和取余 M 的最大值 其实是一道水题... 前缀和 , 然后就是找 ( sum( r ) - sum( l ) ) % M 的最大值 . 考虑一个 sum( r ) ...
- BZOJ 3545: [ONTAK2010]Peaks( BST + 启发式合并 + 并查集 )
这道题很好想, 离线, 按询问的x排序从小到大, 然后用并查集维护连通性, 用平衡树维护连通块的山的权值, 合并就用启发式合并.时间复杂度的话, 排序是O(mlogm + qlogq), 启发式合并是 ...
- BZOJ 3551: [ONTAK2010]Peaks加强版 [Kruskal重构树 dfs序 主席树]
3551: [ONTAK2010]Peaks加强版 题意:带权图,多组询问与一个点通过边权\(\le lim\)的边连通的点中点权k大值,强制在线 PoPoQQQ大爷题解传送门 说一下感受: 容易发现 ...
- BZOJ 3545: [ONTAK2010]Peaks [Splay启发式合并]
3545: [ONTAK2010]Peaks 题意:带权图,多组询问与一个点通过边权\(\le x\)的边连通的点中点权k大值 又读错题了,输出点一直WA,问的是点权啊 本题加强版强制在线了,那这道题 ...
- bzoj3545: [ONTAK2010]Peaks 重构树 主席树
题目链接 bzoj3545: [ONTAK2010]Peaks 题解 套路重构树上主席树 代码 #include<cstdio> #include<algorithm> #de ...
- 【BZOJ3545】 [ONTAK2010]Peaks
BZOJ3545 [ONTAK2010]Peaks Solution 既然会加强版,直接把强制在线的操作去掉就好了. 代码实现 #include<stdio.h> #include< ...
随机推荐
- 2 进程multiprocessing [mʌltɪ'prəʊsesɪŋ] time模块
1.multiprocessing模块 multiprocessing模块就是跨平台版本的多进程模块. multiprocessing模块提供了一个Process类来代表一个进程对象, 2.Proce ...
- 3668: [Noi2014]起床困难综合症
3668: [Noi2014]起床困难综合症 https://www.lydsy.com/JudgeOnline/problem.php?id=3668 分析: 每一位分开考虑. 算出每一位为1,计算 ...
- Redis系列三 Redis数据类型
一 .Redis的五大数据类型 1.String(字符串) string是redis最基本的数据类型,可以理解成与 Memached一模一样的数据类型,一个key对应一个value. string 类 ...
- PHP MySQL 安全方案
1 转义与清除转义 // 对 用户提交的数据 ' " \ 进行转义 if ( get_magic_quotes_gpc() ) { function del_magic_quotes($v ...
- c的多态
使用函数数组,实现多态 参考my_strtoll10
- 一对多,多的逗号分隔存在新字段中(Group_concat 用法)
sql 语句: SELECT ( SELECT Group_concat(t_work_group_user.user_id) FROM ...
- poj3984迷宫问题(dfs+stack)
迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35426 Accepted: 20088 Descriptio ...
- 记录---Testin上新手测试用例设计实战---碎乐3.2.0
平台上给的版本是碎乐3.12版的,但是平台上给的安装包下载不了,所以加群咨询之后给出了直接去手机应用商店下载搜索到的版本的对策.所以就那应用商店中找到的3.2.0版本来设计测试用例.因为任务中没有给出 ...
- Git与远程仓库关联以及关联错误解决方法
假设你github的用户名是 helloworld ,你在上面创建了一个 名为 hello 的 repository. 一. 与本地仓库进行关联 1.1用原生ssh进行关联,速度快: git re ...
- (转载)Unity3d中的属性(Attributes)整理
附加: float字段检视面板修改:[Range(1,10)] 对属性进行分组:[Header("xxx")] 工具栏中调用方法,类文件需在Editor文件夹中:[MenuIte( ...