沈阳网络赛 F - 上下界网络流
"Oh, There is a bipartite graph.""Make it Fantastic."
X wants to check whether a bipartite graph is a fantastic graph. He has two fantastic numbers, and he wants to let all the degrees to between the two boundaries. You can pick up several edges from the current graph and try to make the degrees of every point to between the two boundaries. If you pick one edge, the degrees of two end points will both increase by one. Can you help X to check whether it is possible to fix the graph?
Input
There are at most 303030 test cases.
For each test case,The first line contains three integers NNN the number of left part graph vertices, MMM the number of right part graph vertices, and KKK the number of edges ( 1≤N≤20001 \le N \le 20001≤N≤2000,0≤M≤20000 \le M \le 20000≤M≤2000,0≤K≤60000 \le K \le 60000≤K≤6000 ). Vertices are numbered from 111 to NNN.
The second line contains two numbers L,RL, RL,R (0≤L≤R≤300)(0 \le L \le R \le 300)(0≤L≤R≤300). The two fantastic numbers.
Then KKK lines follows, each line containing two numbers UUU, VVV (1≤U≤N,1≤V≤M)(1 \le U \le N,1 \le V \le M)(1≤U≤N,1≤V≤M). It shows that there is a directed edge from UUU-th spot to VVV-th spot.
Note. There may be multiple edges between two vertices.
Output
One line containing a sentence. Begin with the case number. If it is possible to pick some edges to make the graph fantastic, output "Yes" (without quote), else output "No" (without quote).
样例输入
3 3 7
2 3
1 2
2 3
1 3
3 2
3 3
2 1
2 1
3 3 7
3 4
1 2
2 3
1 3
3 2
3 3
2 1
2 1
样例输出
Case 1: Yes
Case 2: No
题目来源
题意 : 给你左右两侧分别给出 n 个点和 m 个点, 再给你其中的一些边,可以选择其中的任意个边,每次选择会使左右两边的点都增加 1, 要求所有点的范围都在 l ~ r 内, 问是否可行
思路分析 :
打网络赛的时候,我们团队竟没有人想到网络流,多裸的一个题啊,当时就感觉这个可以用二分图去解决,,, 可惜当时并没有学过网络流,,,,
其实呢就是一个上下界网络流的水题,构建的图如下

代码示例 :
using namespace std;
#define ll long long
const int maxn = 1e5+5;
const int inf = 0x3f3f3f3f; int n, m, k;
int l, r;
int sum = 0;
struct node
{
int to, next, flow;
}e[maxn];
int head[maxn];
int cnt; void init(){
cnt = 0; sum = 0;
memset(head, -1, sizeof(head));
}
void addedge(int u, int v, int w){
e[cnt].to = v, e[cnt].flow = w, e[cnt].next = head[u], head[u] = cnt++;
e[cnt].to = u, e[cnt].flow = 0, e[cnt].next = head[v], head[v] = cnt++;
} int dep[maxn], que[maxn];
bool bfs(int s, int t){
memset(dep, 0, sizeof(dep));
dep[s] = 1, que[0] = s;
int head1 = 0, tail = 1;
while(head1 < tail) {
int v = que[head1++];
for(int i = head[v]; i != -1; i = e[i].next){
int to = e[i].to;
if (e[i].flow && !dep[to]){
dep[to] = dep[v]+1;
que[tail++] = to;
}
}
}
return dep[t];
}
int aim;
int dfs(int u, int f1){
if (u == aim || f1 == 0) return f1; int f = 0;
for(int i = head[u]; i != -1; i = e[i].next){
int to = e[i].to;
if (e[i].flow && dep[to] == dep[u]+1){
int x = dfs(to, min(e[i].flow, f1));
e[i].flow -= x, e[i^1].flow += x;
f1 -= x, f += x;
if (f1 == 0) return f;
}
}
if (!f) dep[u] = -2;
return f;
}
int kas = 1; void maxflow(int s, int t){
int res = 0; aim = t; while(bfs(s, t)){
res += dfs(s, inf);
}
if (res == sum) printf("Case %d: Yes\n", kas++);
else printf("Case %d: No\n", kas++);
} int main() {
int u, v; while(~scanf("%d%d%d", &n, &m, &k)){
int s = 0, t = n+m+1;
int ss = t+m+2, tt = n+m+3;
init();
scanf("%d%d", &l, &r);
addedge(t, s, inf);
for(int i = 1; i <= k; i++){
scanf("%d%d", &u, &v);
addedge(u, n+v, 1);
addedge(u, tt, 0);
addedge(ss, n+v, 0);
}
for(int i = 1; i <= n; i++){
addedge(s, i, r-l);
addedge(s, tt, l);
addedge(ss, i, l);
}
for(int i = 1; i <= m; i++){
addedge(n+i, t, r-l);
addedge(n+i, tt, l);
addedge(ss, t, l);
}
sum = l*(m+n);
maxflow(ss, tt);
}
return 0;
}
沈阳网络赛 F - 上下界网络流的更多相关文章
- 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 ...
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- hdu 4940 Destroy Transportation system( 无源汇上下界网络流的可行流推断 )
题意:有n个点和m条有向边构成的网络.每条边有两个花费: d:毁坏这条边的花费 b:重建一条双向边的花费 寻找这样两个点集,使得点集s到点集t满足 毁坏全部S到T的路径的费用和 > 毁坏全部T到 ...
- 算法笔记--最大流和最小割 && 最小费用最大流 && 上下界网络流
最大流: 给定指定的一个有向图,其中有两个特殊的点源S(Sources)和汇T(Sinks),每条边有指定的容量(Capacity),求满足条件的从S到T的最大流(MaxFlow). 最小割: 割是网 ...
- CF#366 704D Captain America 上下界网络流
CF上的题,就不放链接了,打开太慢,直接上题面吧: 平面上有n个点, 第 i 个点的坐标为 ($X_i ,Y_i$), 你需要把每个点染成红色或者蓝色, 染成红色的花费为 r , 染成蓝色的花费为 b ...
- 【BZOJ3876】[AHOI2014&JSOI2014] 支线剧情(无源汇有上下界网络流)
点此看题面 大致题意: 有一张\(DAG\),经过每条边有一定时间,从\(1\)号点出发,随时可以返回\(1\)号点,求经过所有边的最短时间. 无源汇有上下界网络流 这是无源汇有上下界网络流的板子题. ...
- [BZOJ2502]清理雪道 有上下界网络流(最小流)
2502: 清理雪道 Time Limit: 10 Sec Memory Limit: 128 MB Description 滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场 ...
- uoj132/BZOJ4200/洛谷P2304 [Noi2015]小园丁与老司机 【dp + 带上下界网络流】
题目链接 uoj132 题解 真是一道大码题,,,肝了一个上午 老司机的部分是一个\(dp\),观察点是按\(y\)分层的,而且按每层点的上限来看可以使用\(O(nd)\)的\(dp\),其中\(d\ ...
随机推荐
- CF351E Jeff and Permutation
CF351E Jeff and Permutation 贪心好题 考虑每个对能否最小化贡献和 先不考虑绝对值相同情况 发现,对于a,b假设|a|<|b|,那么有无贡献只和b的正负有关!如果a在b ...
- python基础十二之生成器进阶
生成器表达式 (满足条件的元素或其相关的操作 for 元素 in 可迭代对象 if 条件) g = (i for i in range(10)) for i in g: print(i) egg_li ...
- call undefined function openssl_cipher_iv_length
现象: 访问localhost/blog/public时,报错在verdor/framework/src/Illuminate/Encryption/Encrtpter.php的84行,找不到open ...
- 1471 - Defense Lines
After the last war devastated your country, you - as the king of the land of Ardenia - decided it wa ...
- CCPC 2018 吉林 C "JUSTICE" (数学)
传送门 参考资料: [1]:https://blog.csdn.net/mmk27_word/article/details/89789770 题目描述 Put simply, the Justice ...
- 用nodejs创建服务器显示html页面
nodejs版本:v10.14.2 1.首先准备一个简单的html页面 <!DOCTYPE html> <html lang="en"> <head& ...
- tf.contrib.learn.preprocessing.VocabularyProcessor()
tf.contrib.learn.preprocessing.VocabularyProcessor (max_document_length, min_frequency=0, vocabulary ...
- linux测试 scullpipe 驱动
我们已经见到了 scullpipe 驱动如何实现阻塞 I/O. 如果你想试一试, 这个驱动的源码 可在剩下的本书例子中找到. 阻塞 I/O 的动作可通过打开 2 个窗口见到. 第一个可运行 一个命令诸 ...
- dotnet Framework 源代码 · Ink
本文是分析 .NET Framework 源代码的系列,主要告诉大家微软做笔迹用的思路,怎么做的笔迹才是高性能的,用户体验比较好的.我会告诉大家源代码的思想,当然这个文章会比较无聊.如果你是想做笔迹的 ...
- Deep Learning ——Yann LeCun,Yoshua Bengio&Geoffrey Hinton
引言: 深度学习的本质是用多层的神经网络找到一个可以被学习的复杂的函数实现语音识别,图像识别等功能. 多层神经网络的结构: 多层神经元的组成,每一层的输入都等于上一层的输出. 应用领域:cv,nlp ...