"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

题目来源

ACM-ICPC 2018 沈阳赛区网络预赛

题意 : 给你左右两侧分别给出 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 - 上下界网络流的更多相关文章

  1. ACM-ICPC 2018 沈阳赛区网络预赛 F Fantastic Graph(贪心或有源汇上下界网络流)

    https://nanti.jisuanke.com/t/31447 题意 一个二分图,左边N个点,右边M个点,中间K条边,问你是否可以删掉边使得所有点的度数在[L,R]之间 分析 最大流不太会.. ...

  2. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (贪心或有源汇上下界网络流)

    "Oh, There is a bipartite graph.""Make it Fantastic."X wants to check whether a ...

  3. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  4. hdu 4940 Destroy Transportation system( 无源汇上下界网络流的可行流推断 )

    题意:有n个点和m条有向边构成的网络.每条边有两个花费: d:毁坏这条边的花费 b:重建一条双向边的花费 寻找这样两个点集,使得点集s到点集t满足 毁坏全部S到T的路径的费用和 > 毁坏全部T到 ...

  5. 算法笔记--最大流和最小割 && 最小费用最大流 && 上下界网络流

    最大流: 给定指定的一个有向图,其中有两个特殊的点源S(Sources)和汇T(Sinks),每条边有指定的容量(Capacity),求满足条件的从S到T的最大流(MaxFlow). 最小割: 割是网 ...

  6. CF#366 704D Captain America 上下界网络流

    CF上的题,就不放链接了,打开太慢,直接上题面吧: 平面上有n个点, 第 i 个点的坐标为 ($X_i ,Y_i$), 你需要把每个点染成红色或者蓝色, 染成红色的花费为 r , 染成蓝色的花费为 b ...

  7. 【BZOJ3876】[AHOI2014&JSOI2014] 支线剧情(无源汇有上下界网络流)

    点此看题面 大致题意: 有一张\(DAG\),经过每条边有一定时间,从\(1\)号点出发,随时可以返回\(1\)号点,求经过所有边的最短时间. 无源汇有上下界网络流 这是无源汇有上下界网络流的板子题. ...

  8. [BZOJ2502]清理雪道 有上下界网络流(最小流)

    2502: 清理雪道 Time Limit: 10 Sec  Memory Limit: 128 MB Description        滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场 ...

  9. uoj132/BZOJ4200/洛谷P2304 [Noi2015]小园丁与老司机 【dp + 带上下界网络流】

    题目链接 uoj132 题解 真是一道大码题,,,肝了一个上午 老司机的部分是一个\(dp\),观察点是按\(y\)分层的,而且按每层点的上限来看可以使用\(O(nd)\)的\(dp\),其中\(d\ ...

随机推荐

  1. Python--day42--mysql操作数据库及数据表和基本增删改查

    sql语法规则: 一.操作文件夹 1.创建数据库db2:create database db2; 2.创建数据库db2并标明数据库的编码格式为utf8:create database db2 defa ...

  2. java 泛型的嵌套(map例子)

    package july7; //泛型加Map的输出! import java.util.Iterator; import java.util.Map; import java.util.Map.En ...

  3. 查看laravel版本

    方法1: 使用php artisan --version ,只要能看懂这个命令的人一定已经具有初步的Laravel知识.再介绍一种不需要命令,直接去文件中去查看的方法. 方法2: 在项目文件中找ven ...

  4. element 树形控件使用

    <el-tree :data="morkDataList" show-checkbox ref="tree" node-key="id" ...

  5. qt添加cef库嵌入web,linux 下Qt WebEngine 程序打包简单记录

    http://www.cnblogs.com/oloroso/p/6051631.html http://www.cnblogs.com/oloroso/p/6149000.html

  6. IAP升级

    一.IAP原理 1.在正常情况下,程序运行路流程: 和STM32类似,STM8内部闪存(FLASH)地址起始于 0x8000(STM32是0x08000000),一般情况下,程序文件就从此地 址开始写 ...

  7. hadoop fs、hadoop dfs与hdfs dfs命令的区别

    Hadoop fs:使用面最广,可以操作任何文件系统. hadoop dfs与hdfs dfs:只能操作HDFS文件系统相关(包括与Local FS间的操作),前者已经Deprecated,一般使用后 ...

  8. 第二阶段:1.流程图:12.AXURE绘制页面流程图

    注意的事项: 完整的页面流程图

  9. 亲测可用的优雅的在已经安装了python的Ubuntu上安装python3.5

    我的Ubuntu上已经安装了python2.7和3.4. 用以下方法可以方便的顺利的安装python3.5,使用的时候也不会发生冲突. 一条一条输入以下语句 wget https://www.pyth ...

  10. ELK学习实验009:安装kibana的仪表盘

    一 metricbeat仪表盘 1.1 安装metricbeat仪表盘 可以将metricbeat数据在kibana中展示 [root@node4 ~]# cd /usr/local/metricbe ...