ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph(有源上下界最大流 模板)
关于有源上下界最大流: https://blog.csdn.net/regina8023/article/details/45815023
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n, m, k, l, r, s, t, superS, superT;
const int MAXN = ;//点数的最大值
const int MAXM = ;//边数的最大值
const int INF = 0x3f3f3f3f;
struct Edge
{
int to,next,cap,flow; } edge[MAXM]; //注意是MAXM
int tol;
int head[MAXN];
void init()
{
tol = ;
memset(head,-,sizeof(head));
}
void addedge(int u,int v,int w,int rw = )
{
edge[tol].to = v;
edge[tol].cap = w;
edge[tol].flow = ;
edge[tol].next = head[u];
head[u] = tol++;
edge[tol].to = u;
edge[tol].cap = rw;
edge[tol].flow = ;
edge[tol].next = head[v];
head[v] = tol++;
}
int Q[MAXN];
int dep[MAXN],cur[MAXN],sta[MAXN];
bool bfs(int s,int t,int n)
{
int front = ,tail = ;
memset(dep,-,sizeof(dep[])*(n+));
dep[s] = ;
Q[tail++] = s;
while(front < tail)
{
int u = Q[front++];
for(int i = head[u]; i != -; i = edge[i].next)
{
int v = edge[i].to;
if(edge[i].cap > edge[i].flow && dep[v] == -)
{
dep[v] = dep[u] + ;
if(v == t)
return true;
Q[tail++] = v;
}
}
}
return false;
}
int dinic(int s,int t,int n)
{
int maxflow = ;
while(bfs(s,t,n))
{
for(int i = ; i < n; i++)
cur[i] = head[i];
int u = s, tail = ;
while(cur[s] != -)
{
if(u == t)
{
int tp = INF;
for(int i = tail-; i >= ; i--)
tp = min(tp,edge[sta[i]].cap-edge[sta[i]].flow);
maxflow += tp;
for(int i = tail-; i >= ; i--)
{
edge[sta[i]].flow += tp;
edge[sta[i]^].flow -= tp;
if(edge[sta[i]].cap-edge[sta[i]].flow == )
tail = i;
} u = edge[sta[tail]^].to;
}
else if(cur[u] != - && edge[cur[u]].cap > edge[cur[u]].flow && dep[u] + == dep[edge[cur[u]].to])
{
sta[tail++] = cur[u];
u = edge[cur[u]].to;
}
else
{
while(u != s && cur[u] == -)
u = edge[sta[--tail]^].to;
cur[u] = edge[cur[u]].next;
}
}
}
return maxflow;
}
int main()
{
int kase = ;
while(~scanf("%d %d %d", &m, &n, &k))
{
scanf("%d %d", &l, &r);
s = n + m + ;
t = n + m + ;
superS = n + m + ;
superT = n + m + ;
init();
for(int i = ; i <= k; i++)
{
int u, v;
scanf("%d %d", &u , &v);
addedge(u, v + n, ); //二分图 建一条容量为1的边
}
addedge(t,s,INF); //从汇点向源点建一条inf的边
for(int i = ; i <= n; i++){
addedge(s, i, r - l); //从源点向左半图连边
addedge(superS, i, l);
addedge(s, superT, l);
}
for(int i = ; i <= m; i++){
int aim = i + n;
addedge(aim, t, r - l);
addedge(aim, superT, l);
addedge(superS, t, l);
}
printf("Case %d: ", kase++);
int ans = dinic(superS, superT, n+m+);
if(ans == (n+m)*l) puts("Yes");
else puts("No");
}
return ;
}
ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph(有源上下界最大流 模板)的更多相关文章
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (上下界网络流)
正解: #include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN=1 ...
- 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 ...
- Fantastic Graph 2018 沈阳赛区网络预赛 F题
题意: 二分图 有k条边,我们去选择其中的几条 每选中一条那么此条边的u 和 v的度数就+1,最后使得所有点的度数都在[l, r]这个区间内 , 这就相当于 边流入1,流出1,最后使流量平衡 解析: ...
- ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(第k短路模板)
求第k短路模板 先逆向求每个点到终点的距离,再用dij算法,不会超时(虽然还没搞明白为啥... #include<iostream> #include<cstdio> #inc ...
- ACM-ICPC 2018 沈阳赛区网络预赛-D:Made In Heaven(K短路+A*模板)
Made In Heaven One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. ...
- 图上两点之间的第k最短路径的长度 ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven
131072K One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. Howe ...
- ACM-ICPC 2018 沈阳赛区网络预赛 K Supreme Number(规律)
https://nanti.jisuanke.com/t/31452 题意 给出一个n (2 ≤ N ≤ 10100 ),找到最接近且小于n的一个数,这个数需要满足每位上的数字构成的集合的每个非空子集 ...
随机推荐
- Java编码优化
Java编码优化 1.尽可能使用局部变量 调用方法时传递的参数以及在调用中创建的临时变量都保存在栈中速度较快,其他变 量,如静态变量.实例变量等,都在堆中创建,速度较慢.另外,栈中创建的变量,随 着方 ...
- cas 单点登录服务端客户端配置
首先,下载 cas-server-3.5.2-release http://pan.baidu.com/s/1GJ8Gs cas-client-3.2.1-release http://pan.bai ...
- C# 加密、解密函数
#region ========加密======== /// <summary> /// 加密 /// </summary> /// <param name=" ...
- MS-SQL 时间的操作
1. 当前系统日期.时间 select getdate() 2. dateadd 在向指定日期加上一段时间的基础上,返回新的 datetime 值 例如:向日期加上2天 select dateadd ...
- PreparementStatement接口
1.SQL注入问题在以前过程中,总是采取拼接SQL语句的方式,来实现数据的增删改查! String Sql=select * from user where username="" ...
- Redis hash(哈希)
Redis hash可储存多个键值对,适合储存对象的属性. 1.hset key fieldName fileValue //hset即hash set,set这里是设置的意思.往hash中添加 ...
- Git 连接远程仓库Github
创建SSH Key. 在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接跳到下一步. 如果没有,打开Shell(W ...
- JavaWeb_02_CSS学习
CSS简介 Cascading Style Sheets (CSS)层叠样式表:en.wikipedia.org 层叠:一层一层的叠加样式 样式表:提供更多属性和属性值实现更多样式变化 css将显示样 ...
- ios 根据字典自动生成属性
- (void)createPropertyCode{ NSMutableString *codes = [NSMutableString string]; // 遍历字典 [self enumera ...
- GIT新手入门学习教程
廖雪峰的GIT教程 链接地址:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000