【BNUOJ】Another Server
来源:互联网 发布:知乎为什么垃圾 编辑:程序博客网 时间:2024/05/17 02:00
第十五届北京师范大学程序设计竞赛决赛
A. Another Server
何老师某天在机房里搞事情的时候,发现机房里有
显然这些服务器之间要进行信息交换,为了测试服务器的抗压能力,你需要帮何老师计算出
(该图引用自百度百科)
Input
第一行是一个正整数
第二行包含
Output
对于每组测试数据,输出一个整数,表示
Sample Input
2
2
1 1
3
1 3 2 4
Sample Output
2
4
Hint
题解
以
代码
#include <bits/stdc++.h>using namespace std;const int maxn = 510;const int inf = 1e9+1;int T, n, m;int head[maxn], nxt[maxn], to[maxn], flow[maxn], mxflow[maxn], cnt;int dep[maxn], q[maxn], cur[maxn];bool vis[maxn];void add(int a, int b, int c){ nxt[++ cnt] = head[a], to[head[a] = cnt] = b, mxflow[cnt] = c, flow[cnt] = 0; nxt[++ cnt] = head[b], to[head[b] = cnt] = a, mxflow[cnt] = 0, flow[cnt] = 0;}bool bfs(){ for(int i = 1; i <= n; i ++){ vis[i] = 0, dep[i] = 0; } int l = 1, r = 0; q[++ r] = 1, vis[1] = 1, dep[1] = 1; while(l <= r){ int x = q[l ++]; for(int i = head[x]; i; i = nxt[i]){ int u = to[i]; if(!vis[u] && flow[i] < mxflow[i]){ q[++ r] = u, dep[u] = dep[x] + 1, vis[u] = 1; } } } return vis[n];}int dfs(int x, int mr){ if(x == n || mr == 0) return mr; int &i = cur[x]; int f = 0, res = 0, u; for( ; i; i = nxt[i]){ u = to[i]; if(dep[x]+1 == dep[u] && (f = dfs(u, min(mr, mxflow[i] - flow[i])))){ flow[i] += f, flow[i^1] -= f; mr -= f, res += f; } if(mr == 0) break; } return res;}int dinic(){ int res = 0; while(bfs()){ for(int i = 1; i <= n; i ++) cur[i] = head[i]; res += dfs(1, inf); } return res;}int main(){ scanf("%d", &T); while(T --){ scanf("%d", &n); m = 2*n-2, cnt = 1; for(int i = 1; i <= n; i ++) head[i] = 0; for(int i = 1; i <= m; i ++){ int v; scanf("%d", &v); add((i+1)/2, (i+1)/2+1, v); } printf("%d\n", dinic()); } return 0;}
0 0
- 【BNUOJ】Another Server
- Another Server(BNUOJ 同步赛)
- Another Server
- Migrate table to another Oracle Server-01
- XAMPP: Another web server is already running
- Another Server(语文功底题)
- another
- ANother
- another
- How to use HttpWebRequest to post data to another page which is on another server
- BNUOJ 1777
- BNUOJ 6242
- 四叉树 bnuoj
- BNUOJ 14519
- BNUOJ 8108
- BNUOJ 8108
- sql server 2008 copy data from one table to another
- Transfer postgres database to another server - backup and restore
- Java线程:Callable和Future
- 搬家公告
- CSS—定位与浮动
- 文件缓冲区刷新规则
- [BZOJ2584][Wc2012]memory(扫描线+splay+线段树)
- 【BNUOJ】Another Server
- 2017/04/22
- POJ 3301 (坐标变换、三分枚举计算 点集最小正方形覆盖)
- win10 远程桌面连接失败
- AutoCpmpleteTextView
- emacs作为python2.7 IDE的配置
- 经典卷积神经网络介绍
- 关于JTAG——韦东山嵌入式Linux视频学习笔记02
- 练习