沈阳网络赛 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\ ...
随机推荐
- python基础十五之递归函数
递归函数,在函数中调用自身函数,就会形成一个递归函数.例如: def recursion(n): n += 1 print(n) recursion(n) 由于递归函数的结构,在函数调用时,它会一直调 ...
- python基础六之编码
python中编码的特点: 1,各个编码之间的二进制是不能互相识别的,会产生乱码 2,文件的储存和传输是不能用Unicode的 python3的编码 在python3中字符串在内存中是用Unicode ...
- Xshell + SVN使用
切换目录 cd+想跳转到的目录下 文件浏览 ls ll (ll 信息全) svn更新 svn up 编辑 vi vi的命令 文件保存与退出: :q 在文件未作任何修改的情况下退出. :q! 强制退出, ...
- springboot中使用spring-session实现共享会话到redis(二)
上篇文章介绍了springboot中集成spring-session实现了将session分布式存到redis中.这篇在深入介绍一些spring-session的细节. 1.session超时: 在t ...
- 【u107】数字游戏(bds)
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 有这么一个游戏: 写出一个1-N的排列a[i],然后每次将相邻两个数相加,构成新的序列,再对新序列进行 ...
- Linux 内核kobject非 缺省属性
在许多情况中, kobject 类型的 default_attrs 成员描述所有的 kobject 会拥有的属性. 但是那不是一个设计中的限制; 属性随意可以添加到和删除自 kojects. 如果你想 ...
- gitLab操作规范和项目流程
刚做完一个项目并且艰难得上线,对整个项目流程和gitLab规范 有了一些心得,给新来的同学普及一下. 最先产品会写一篇需求文档,咱们要先看需求文档对项目有一个大致了解,然后产品喊后端.ui.前端 一 ...
- vue权限篇
前言 在一个项目中,一些功能会涉及到重要的数据管理,为了确保数据的安全,我们会在项目中加入权限来限制每个用户的操作.作为前端,我们要做的是配合后端给到的权限数据,做页面上的各种各样的限制. 需求 因为 ...
- git无密码push
近来项目中调研,jupyterlab和git的整合内容,git server我使用的gitbucket和bitbucket.(项目要求使用bitbucket,看错一个字母下载了两个镜像) gitbuc ...
- k8s的网络方案对比
如下图,三台虚拟机k8s-master.k8s-node-1.k8s-node-2组成k8s集群,网络拓扑和节点IP分配如下图: 一.flannel组网方案 https://github.com/co ...