2018沈阳网赛F--上下界网络流
建图:
首先加一个源点s和汇点t,分别连接在二分图的左边和右边,每条弧的上下界为【L, R】,二分图左边和右边之间连弧上下界为【0,1】,其实就相当于连弧为1。
然后问题就转换为:有源汇最大流。
继续建图:
建立弧<t,s><,容量下界为00,上界为∞∞。
加一个超级源ss和超级汇tt
对于所有有上下界的弧(也就是s,t分别连接左边和右边的弧)进行分边
一条为<ss,v>,容量为L;
一条为<u,tt>>,容量为L;
一条为<u,v>,容量为R-L。
其中前两条弧一般称为附加弧。
然后跑一遍最大流,如果ss所有的出边(或者是TT所有的入边)都满流,就输出Yes
以后再加图说明吧....
(代码说明一下.. 0为超级源,NV为超级汇, NV-2为源, NV-1为汇)
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int N = ;
const int inf = 0x3f3f3f; struct Edge
{
int from,to,cap,flow;
Edge(int u,int v,int c,int f):from(u),to(v),cap(c),flow(f) {}
}; struct Din
{
int s,t;
vector<Edge>edges;
vector<int>G[N];
bool vis[N];
int d[N];
int cur[N]; void addedge(int from,int to,int cap)
{
edges.push_back(Edge(from,to,cap,));
edges.push_back(Edge(to,from,,));
int m=edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
} bool bfs()
{
memset(vis,,sizeof(vis));
queue<int>Q;
Q.push(s);
d[s]=;
vis[s]=;
while(!Q.empty())
{
int x=Q.front();
Q.pop();
for(int i=; i<G[x].size(); i++)
{
Edge&e=edges[G[x][i]];
if(!vis[e.to]&&e.cap>e.flow)
{
vis[e.to]=;
d[e.to]=d[x]+;
Q.push(e.to);
}
}
}
return vis[t];
} int dfs(int x,int a)
{
if(x==t||a==)
return a;
int flow=,f;
for(int i=cur[x]; i<G[x].size(); i++)
{
Edge&e=edges[G[x][i]];
if(d[x]+==d[e.to]&&(f=dfs(e.to,min(a,e.cap-e.flow)))>)
{
e.flow += f;
edges[G[x][i]^].flow -= f;
flow += f;
a -= f;
if(!a)
break;
}
}
return flow;
} int Maxflow(int s,int t)
{
this->s=s,this->t=t;
int flow=;
while(bfs())
{
memset(cur,,sizeof(cur));
flow += dfs(s,inf);
}
return flow;
}
}; int main()
{
int N,F,D;
int cnt = ;
while(scanf("%d%d%d",&N,&F,&D) != EOF)
{
Din tmp;
int flag = ;
int NV = N+F++, NE=;
int a, b;
int l, r;
scanf("%d%d",&l, &r);
for(int i=; i<D; i++)
{
scanf("%d%d",&a, &b);
tmp.addedge(a,N+b, );
}
for(int i=; i<=N; i++)
{
tmp.addedge(NV-,i, r-l);
tmp.addedge(,i, l);
tmp.addedge(NV-,NV, l);
}
for(int i=; i<=F; i++)
{
tmp.addedge(N+i,NV-, r-l);
tmp.addedge(,NV-, l);
tmp.addedge(N+i,NV, l);
}
tmp.addedge(NV-,NV-, inf);
int tt = tmp.Maxflow(NE,NV);
for(int i=; i<tmp.G[].size(); i++)
{
Edge &e=tmp.edges[tmp.G[][i]];
if(e.flow < l){
flag = ;
break;
}
}
cnt++;
if(flag)
printf("Case %d: Yes\n", cnt);
else
printf("Case %d: No\n", cnt);
}
}
2018沈阳网赛F--上下界网络流的更多相关文章
- 沈阳网络赛 F - 上下界网络流
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F Fantastic Graph(贪心或有源汇上下界网络流)
https://nanti.jisuanke.com/t/31447 题意 一个二分图,左边N个点,右边M个点,中间K条边,问你是否可以删掉边使得所有点的度数在[L,R]之间 分析 最大流不太会.. ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (贪心或有源汇上下界网络流)
"Oh, There is a bipartite graph.""Make it Fantastic."X wants to check whether a ...
- hdu 4940 Destroy Transportation system( 无源汇上下界网络流的可行流推断 )
题意:有n个点和m条有向边构成的网络.每条边有两个花费: d:毁坏这条边的花费 b:重建一条双向边的花费 寻找这样两个点集,使得点集s到点集t满足 毁坏全部S到T的路径的费用和 > 毁坏全部T到 ...
- 算法笔记--最大流和最小割 && 最小费用最大流 && 上下界网络流
最大流: 给定指定的一个有向图,其中有两个特殊的点源S(Sources)和汇T(Sinks),每条边有指定的容量(Capacity),求满足条件的从S到T的最大流(MaxFlow). 最小割: 割是网 ...
- [BZOJ2502]清理雪道 有上下界网络流(最小流)
2502: 清理雪道 Time Limit: 10 Sec Memory Limit: 128 MB Description 滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场 ...
- uoj132/BZOJ4200/洛谷P2304 [Noi2015]小园丁与老司机 【dp + 带上下界网络流】
题目链接 uoj132 题解 真是一道大码题,,,肝了一个上午 老司机的部分是一个\(dp\),观察点是按\(y\)分层的,而且按每层点的上限来看可以使用\(O(nd)\)的\(dp\),其中\(d\ ...
- 【有上下界网络流】【ZOJ】2314 Reactor Cooling
[算法]有上下界网络流-无源汇(循环流) [题解]http://www.cnblogs.com/onioncyc/p/6496532.html //未提交 #include<cstdio> ...
- CF#366 704D Captain America 上下界网络流
CF上的题,就不放链接了,打开太慢,直接上题面吧: 平面上有n个点, 第 i 个点的坐标为 ($X_i ,Y_i$), 你需要把每个点染成红色或者蓝色, 染成红色的花费为 r , 染成蓝色的花费为 b ...
随机推荐
- nginx与二级域名的绑定 nginx安装
nginx中文文档 http://www.nginx.cn/doc/ nginx 查看配置文件地址 http://blog.csdn.net/ljfrocky/article/details/5052 ...
- UE4模型导入基础教程
转自:http://www.unrealchina.net/portal.php?mod=view&aid=290
- 【转】Rails 4中使用 Bootstrap 3
转自:http://rvg.me/2013/11/using-bootstrap-3-with-rails-4/ If you are looking to use Bootstrap 3 with ...
- HDLM命令dlnkmgr详解之四_monitor/offline/online
1. monitor 以一定的时间间隔监控hba或cha口的IO信息. 命令格式 监控hba口的IO信息: dlnkmgr monitor -hbaid HBA_ID [-intvl Interval ...
- Solaris10安装配置LDAP(iPlanet Directory Server )
Solaris10安装光盘自带了iPlanet Directory Server安装包,系统管理员可以利用iPlanet Directory Server在Solaris系统创建一个LDAP Serv ...
- git pull没有指定branch的报错
执行git pull或者git push的时,有时候会出现如下报错: $ git pull You asked me to pull without telling me which branch y ...
- Internet Intranet Extranet
Internet: There's only one of it, and you're on it now. Intranet: An internal network local to a com ...
- 【总结整理】display与position之间的关系【较完整】(转)
display与position之间的关系 以防自己忘记写的 网上找的 positon 与 display 的相互关系 元素分为内联元素和区块元素两类(当然也有其它的),在内联元素中有个非常重要的 ...
- 解决iText+freemark导出pdf不支持base64的解决办法
工具类: package test; import java.io.IOException ; import org.w3c.dom.Element ; import org.xhtmlrendere ...
- IPv6地址在URL上的格式
转自:http://www.cnpaf.net/Class/RFC/200408/983.html 摘要 本文档定义了在WWW浏览器的URL中执行的文本IPv6地址的格式.在包括Microsoft的I ...