"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?
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.
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
#include
#include
#include
#include
#include
#include
上下限网络流的算法正在学习中......