"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. js(二) 实现省市联动(json)

    通过HTML页面的city的select选取的value值,从json里面获取相对应的键值对,最后将值拼接到下拉框中 function x1(th) { //通过传入的th的value获取相对应的ci ...

  2. DIRECTORY_SEPARATOR 与 getcwd

    DIRECTORY_SEPARATOR:目录分隔符,linux上就是’/’    windows上是’\’ ,php的内置常量是一个显示系统分隔符的命令,php的内部常量,不需要任何定义与包含即可直接 ...

  3. vue v-for循环中key属性的使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. H3C IP地址动态获取过程

  5. ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(10)之素材管理

    源码下载地址:http://www.yealuo.com/Sccnn/Detail?KeyValue=c891ffae-7441-4afb-9a75-c5fe000e3d1c 素材管理模块也是我们这个 ...

  6. vue-learning:39 - router - vue-router的基本使用

    vue-router路由的基本使用 一张图阐述vue-router的基本使用步骤 // 0. 如果全局使用CDN引入:vue 引入在前,vue-router引入在后 // <script src ...

  7. dll中全局变量在外部进行引用

    在Windows中实际导出全局变量,您必须使用类似于export / import语法的语法,例如: #ifdef COMPILING_THE_DLL #define MY_DLL_EXPORT ex ...

  8. 2018-8-10-win10-uwp-修改Pivot-Header-颜色

    title author date CreateTime categories win10 uwp 修改Pivot Header 颜色 lindexi 2018-08-10 19:17:19 +080 ...

  9. VS code 汉化及快捷键修改

    VsCode汉化方式 Vscode是一款开源的跨平台编辑器.默认情况下,vscode使用的语言为英文(us),如何将其显示语言修改成中文了? 打开vscode工具: 点击左侧的Extensions(拓 ...

  10. codeforces 1136E 线段树

    codeforces 1136E: 题意:给你一个长度为n的序列a和长度为n-1的序列k,序列a在任何时候都满足如下性质,a[i+1]>=ai+ki,如果更新后a[i+1]<ai+ki了, ...