[网络流]Drainage Ditches(草地排水)
Drainage Ditches(草地排水)
题目描述
在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水。这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间。因此,农夫约翰修建了一套排水系统来使贝茜的草地免除被大水淹没的烦恼(不用担心,雨水会流向附近的一条小溪)。作为一名一流的技师,农夫约翰已经在每条排水沟的一端安上了控制器,这样他可以控制流入排水沟的水流量。
农夫约翰知道每一条排水沟每分钟可以流过的水量,和排水系统的准确布局(起点为水潭而终点为小溪的一张网)。需要注意的是,有些时候从一处到另一处不只有一条排水沟。
根据这些信息,计算从水潭排水到小溪的最大流量。对于给出的每条排水沟,雨水只能沿着一个方向流动,注意可能会出现雨水环形流动的情形。。
输入
第1行: | 两个用空格分开的整数N (0 <= N <= 200) 和 M (2 <= M <= 200)。N是农夫约翰已经挖好的排水沟的数量,M是排水沟交叉点的数量。交点1是水潭,交点M是小溪。 |
第二行到第N+1行: | 每行有三个整数,Si, Ei, 和 Ci。Si 和 Ei (1 <= Si, Ei <= M) 指明排水沟两端的交点,雨水从Si 流向Ei。Ci (0 <= Ci <= 10,000,000)是这条排水沟的最大容量。 |
输出
输出一个整数,即排水的最大流量。
样例输入
- 5 4
- 1 2 40
- 1 4 20
- 2 4 20
- 2 3 30
- 3 4 10
样例输出
- 50
- 就是一道模板题QAQQ
本蒟蒻花了20分钟调结果发现"%d%d%d"写成"%d%d&d"
美滋滋~
代码:
- #include<algorithm>
- #include<cstdio>
- #include<cstring>
- #include<queue>
- const int Maxv = , INF = 0x6ffffff;
- int Dep[Maxv], W[Maxv], V[Maxv], Head[Maxv], Next[Maxv], cnt, n, s = , t;
- void Add(int u, int v, int w){
- cnt++;
- Next[cnt] = Head[u];
- V[cnt] = v;
- W[cnt] = w;
- Head[u] = cnt;
- }
- void Add_Edge(int u, int v, int w){
- Add(u, v, w);
- Add(v, u, );
- }
- bool BFS(){
- std::queue<int> Q;
- while (!Q.empty()) {
- Q.pop();
- }
- memset(Dep, , sizeof(Dep));
- Dep[s] = ;
- Q.push(s);
- while (!Q.empty()) {
- int u = Q.front();
- Q.pop();
- for (int i = Head[u]; ~i; i = Next[i]) {
- if (W[i] > && Dep[V[i]] == ) {
- Dep[V[i]] = Dep[u] + ;
- Q.push(V[i]);
- }
- }
- }
- if (Dep[t] > ) {
- return true;
- }
- return false;
- }
- int DFS(int u, int dist){
- if (u == t) {
- return dist;
- }
- for (int i = Head[u]; ~i; i = Next[i]) {
- if (Dep[V[i]] == Dep[u] + && W[i] != ) {
- int di = DFS(V[i], std::min(dist, W[i]));
- if (di > ) {
- W[i] -= di;
- W[i ^ ] += di;
- return di;
- }
- }
- }
- return ;
- }
- int Dinic(){
- int Ans = ;
- while (BFS()) {
- while (int d = DFS(s, INF)) {
- Ans += d;
- }
- }
- return Ans;
- }
- int main(){
- int x, y, val;
- scanf("%d%d", &n, &t);
- memset(Head, - ,sizeof(Head));
- memset(Next, - ,sizeof(Next));
- for (int i = ; i <= n; i++) {
- scanf("%d%d%d", &x, &y, &val);
- Add_Edge(x, y, val);
- }
- printf("%d", Dinic());
- return ;
- }
[网络流]Drainage Ditches(草地排水)的更多相关文章
- 【USACO】草地排水
Drainage Ditches 草地排水 usaco 4.2.1描述在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一 ...
- USACO 4.2 Drainage Ditches(网络流模板题)
Drainage DitchesHal Burch Every time it rains on Farmer John's fields, a pond forms over Bessie's fa ...
- POJ 1273 Drainage Ditches(网络流,最大流)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
- 【网络流】POJ1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 78671 Accepted: 3068 ...
- POJ1273 Drainage Ditches (网络流)
Drainage Ditches Time Limit: 1000MS Memor ...
- HDU 1532 Drainage Ditches (网络流)
A - Drainage Ditches Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- HDU-1532 Drainage Ditches,人生第一道网络流!
Drainage Ditches 自己拉的专题里面没有这题,网上找博客学习网络流的时候看到闯亮学长的博客然后看到这个网络流入门题!随手一敲WA了几发看讨论区才发现坑点! 本题采用的是Edmonds-K ...
- - > 网络流(草地排水)
网络流(Dinic(模板)) Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- POJ 1273 Drainage Ditches (网络流Dinic模板)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
随机推荐
- mysql 数据导出
windowos: select * from pj_zzspdz_fpmx order by kprq desc LIMIT 0,1000000 into outfile 'd:\fpmx.xls ...
- 微信小程序-获取当前城市位置及再次授权地理位置
微信小程序-获取当前城市位置 1. 获取当前地理位置,可通过wx.getLocation接口,返回经纬度.速度等信息; 注意---它的默认工作机制: 首次进入页面,调用该api,返回用户授权结果,并保 ...
- HTML5将<video>视频设置为页面动态背景
<!DOCTYPE html><html><head> <title>Operation Aborted Example</title> & ...
- linux安装后不显示网卡信息
虚拟机安装CentOS 6.4之后,ifconfig只现实lo接口的信息,没有显示eth0网卡的信息,进入/etc/sysconfig/network-scripts/目录中,可以看到ifcfg-et ...
- React设置宽度的坑
[React设置宽度的坑] 我们知道通过ref可以获取DOM元素,通过style属性可以给此DOM元素添加样式. 但下面两行的赋值是无效的: this.HomeRootDiv.style.width= ...
- 使用tor网络
在www.torproject.org/projects/torbrowser.html.en上找到合适的版本下载 下载好tor浏览器之后,解压双击Tor Browser,出现这个错误 这是因为kal ...
- 二、Blender/Python API总览
原文:https://docs.blender.org/api/blender_python_api_current/info_overview.html Python in Blender Ble ...
- PHPActiveRecord validates
validates_presence_of #检测是不是为空 为空的话可以抛出异常 *Model类: static $validates_presence_of = array( array('tit ...
- telnet ip/域名 端口 是否成功
有时候会ping ip 通,但是telnet不通,可能端口未开. telnet不成功,则显示不能打开到主机的链接,链接失败 . telnet成功,则进入telnet页面(全黑的),证明端口可用.
- jenkin、SVN、archery集成openLDAP
jenkins: 1.下载.安装插件 LDAP .Matrix Authorization Strategy 2. 系统管理 —> 全局安全配置 点击 启用安全,并且选择 LDAP 认证,这里有 ...