"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 3030 test cases.

For each test case,The first line contains three integers NN the number of left part graph vertices, MM the number of right part graph vertices, and KK the number of edges ( 1 \le N \le 20001≤N≤2000,0 \le M \le 20000≤M≤2000,0 \le K \le 60000≤K≤6000 ). Vertices are numbered from 11to NN.

The second line contains two numbers L, RL,R (0 \le L \le R \le 300)(0≤L≤R≤300). The two fantastic numbers.

Then KK lines follows, each line containing two numbers UU, VV (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 UU-th spot to VV-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 沈阳赛区网络预赛

题意:

有一个二分图 每个节点的初始分数为0

每选一条边 边的端点的分数都加1

问如果要求最后所有端点的分数都在l和r之间 可不可以做到

思路:

比赛的时候凌晓突然说这个是上下限网络流的模板题

于是一大帮人就想着怎么改模板 一直到比赛结束都没有改出来

真的没想到居然可以贪心 还好名额拿到了......

很简单的策略:

相当于删除一些边 使得节点的度数在l和r之间 最后剩下的边就是选择的边

枚举每条边 如果u, v的度都大于R 那么这条边肯定可以删掉

如果u的度大于R, v的度小于R却大于L 那么这条边也可以删掉

同理 uv交换也是

如果本来uv的度就在LR之间 就不用管了

最后检查每一个节点的度是不是在LR之间 结束

贪心AC:


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<cstring>
#include<set>
//#include<bits/stdc++.h>
#define inf 0x7f7f7f7f7f7f7f7f
using namespace std;
typedef long long LL; const int maxk = 6005;
const int maxn = 4005;
int n, m, k, l, r;
struct edge {
int u, v;
}e[maxk];
int degree[maxn]; void init()
{
memset(degree, 0, sizeof(degree));
} int main()
{
int cas = 1;
while (scanf("%d%d%d", &n, &m, &k) != EOF) {
init();
scanf("%d%d", &l, &r);
for (int i = 0; i < k; i++) {
scanf("%d%d", &e[i].u, &e[i].v);
e[i].v += n;
degree[e[i].u]++;
degree[e[i].v]++;
} for (int i = 0; i < k; i++) {
int a = e[i].u, b = e[i].v;
if (degree[a] > r && degree[b] > r) {
degree[a]--;
degree[b]--;
}
else if (degree[a] > l || degree[b] > l) {
degree[a]--;
degree[b]--;
}
} bool flag = true;
for (int i = 1; i <= n + m; i++) {
if (degree[i] > r || degree[i] < l) {
flag = false;
break;
}
}
if (flag) {
printf("Case %d: Yes\n", cas++);
}
else {
printf("Case %d: No\n", cas++);
}
}
return 0;
}

上下限网络流的算法正在学习中......

沈阳网络赛F-Fantastic Graph【贪心】or【网络流】的更多相关文章

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

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

  2. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (上下界网络流)

    正解: #include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN=1 ...

  3. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph

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

  4. 沈阳网络赛 F - 上下界网络流

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

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

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

  6. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph(有源上下界最大流 模板)

    关于有源上下界最大流: https://blog.csdn.net/regina8023/article/details/45815023 #include<cstdio> #includ ...

  7. 2018 ICPC 沈阳网络赛

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

  8. ACM-ICPC 2019南昌网络赛F题 Megumi With String

    ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...

  9. 计蒜客 31447 - Fantastic Graph - [有源汇上下界可行流][2018ICPC沈阳网络预赛F题]

    题目链接:https://nanti.jisuanke.com/t/31447 "Oh, There is a bipartite graph.""Make it Fan ...

随机推荐

  1. PhoneGap开发不可或缺的五件装备

    PhoneGap是一种介于WebApp和NativeApp之间的解决方案,它为每种移动客户端提供一个Native的壳,这种壳里边包着一个Web应 用.借助于壳,Web应用可以被安装,可以被发布到各大市 ...

  2. openstack热迁移和冷迁移

    转自: http://www.cnblogs.com/pycode/p/6494848.html 迁移类型: *非在线迁移 (有时也称之为‘迁移’).也就是在迁移到另外的计算节点时的这段时间虚拟机实例 ...

  3. CentOS系统资源常用命令

    系统: # uname -a   # 查看内核/操作系统/CPU信息 # cat /etc/issue # cat /etc/redhat-release # 查看操作系统版本 # cat /proc ...

  4. Js Object转化为json,json转Object

    var obj={x:10,y:50};var t= JSON.stringify(obj);console.log(typeof t);var gg= JSON.parse(t);console.l ...

  5. 【Java面试题】27 多线程笔试面试概念问答

    第一题:线程的基本概念.线程的基本状态及状态之间的关系? 线程,有时称为轻量级进程,是CPU使用的基本单元:它由线程ID.程序计数器.寄存器集合和堆栈组成.它与属于同一进程的其他线程共享其代码段.数据 ...

  6. jQuery中 wrap() wrapAll() 与 wrapInner()的差异

    wrap() 方法把每个被选元素放置在指定的 HTML 内容或元素中.jQuery 文档操作 - wrapAll() 方法 wrapAll() 在指定的 HTML 内容或元素中放置所有被选的元素.jQ ...

  7. poj 3414 Pots(广搜BFS+路径输出)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:id=3414">http://poj.org/probl ...

  8. 如何用MathType编辑化学等式

    MathType在数学中应用非常广泛,被大量用于编辑数学公式,MathType不仅可以用来编辑数学公式,还可以编辑化学反应式,那么MathType编辑化学等式怎么操作的呢? 具体操作如下: 1.打开M ...

  9. IPV6设置

    C:\Windows\System32\drivers\etc 目录下修改hosts文件. 网上有更新的ipv6 hosts文件,复制下来~ 别人不断更新的: https://raw.githubus ...

  10. linux系统中,查看当前系统中,都在监听哪些端口

    需求描述: 查看当前系统中都监听着哪些的端口,用netstat命令,在此记录下 操作过程: 1.查看系统中都在监听哪些端口 [root@testvm home]# netstat -ntl Activ ...