POJ 1273(EK)
题目大概意思是,有N条水沟和M个水池,问从第一个水池到最后一个水池在同一时间内能够流过多少水
第一行有两个整数N,M
接下来N行,每行有3个整数,a,b,c,代表从a到b能够流c单位的水
超级模板题,一个有向图,源点为1,汇点为M,套最大流模板就行了
我就通过这水题理解EK的...
#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<climits>
using namespace std;
#define N 210
#define clr(a,b) memset(a,b,sizeof(a))
int cap[N][N];///容量
int n,m;
int a,b,c;
int EK(int s,int t)///s代表源点,t代表汇点
{
queue<int> q;
int flow[N][N];///流量
int low[N];///low[v]表示s-v的最小残量
int pre[N];///用于BFS寻找父亲节点
int u,v;
int maxflow = ;///最大流
clr(flow,);///初始时残量网络为0
while()
{
q.push(s);///把源点压入队列中
clr(low,);
low[s] = INT_MAX;
while(!q.empty())
{
u = q.front();
q.pop();
for(v = ; v <= t; v ++)
{
if(!low[v] && cap[u][v] > flow[u][v])///找到新节点v
{
q.push(v);
low[v] = min(low[u], cap[u][v] - flow[u][v]);
pre[v] = u;
}
}
}
if(low[t] == ) break;///找不到,则当前流已经是最大
for(u = t; u != s; u = pre[u])
{
flow[pre[u]][u] += low[t];
flow[u][pre[u]] -= low[t];
}
maxflow += low[t];
}
return maxflow;
}
int main()
{
int ans;
while(~scanf("%d%d",&n,&m))
{
clr(cap,); for(int i=; i<n; i++)
{
scanf("%d%d%d",&a,&b,&c);
cap[a][b] += c;
}
ans = EK(,m);
printf("%d\n",ans);
}
return ;
}
POJ 1273(EK)的更多相关文章
- UVA 820 --- POJ 1273 最大流
找了好久这两个的区别...UVA820 WA了 好多次.不过以后就做模板了,可以求任意两点之间的最大流. UVA 是无向图,因此可能有重边,POJ 1273是有向图,而且是单源点求最大流,因此改模板的 ...
- POJ 1273 Drainage Ditches(网络流dinic算法模板)
POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
- Poj(1273),最大流,EK
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 69355 Accepted: 2687 ...
- poj 1273 Drainage Ditches(最大流,E-K算法)
一.Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clove ...
- poj 1273 最大流
题目链接:http://poj.org/problem?id=1273 a.EK算法:(Edmond-Karp): 用BFS不断找增广路径,当找不到增广路径时当前流量即为最大流. b.dinic算法: ...
- POJ 1273 网络流(最大流)模板
http://poj.org/problem?id=1273 这道题很值得反思,弄了一下午,交上去先是一直编译错误,而在本地运行没有问题, 原因可能是oj的编译器版本老旧不支持这样的写法 G[from ...
- poj 1273 Drainage Ditches 最大流入门题
题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...
- poj 1273 Drainage Ditches(最大流)
http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
随机推荐
- 基于CSS3制作的鼠标悬停动画菜单
之前分享了好多款css3实现的鼠标悬停效果.今天再给大家带来一款基于CSS3制作的鼠标悬停动画菜单.这款菜单适用浏览器:360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界 ...
- reactor官方文档译文(1)Reactor简介
原文地址:http://projectreactor.io/docs/reference/ Reactor简介 Reactor是一个基础库,用在构建实时数据流应用.要求有容错和低延迟至毫秒.纳秒.皮秒 ...
- Laravel 5.1使用命令行模式(artisan)运行php脚本
Laravel有内置命令调度器,可以方便的实现Cron. 任务调度定义在app/Console/Kernel.php文件的schedule方法中,该方法已经包含了一个示例.Laravel里有两种方法执 ...
- LeetCode39 Combination Sum
题目: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C ...
- java操作spark1.2.0
虽然推荐的是scala,但是还是试一下 package org.admln.java7OperateSpark; import java.util.Arrays; import java.util.L ...
- C# Hook钩子实例代码之截取键盘输入,需要的朋友可以参考下
一.关于本文 以最通俗的语言说明钩子的使用方法,具体到钩子的详细介绍可以参照下面的网址: http://www.microsoft.com/china/community/program/origin ...
- 利用map可以对很大的数出现的次数进行记数
Problem Description In the year 8888, the Earth is ruled by the PPF Empire . As the population growi ...
- entity framework 连接 oracle 发布后出现的问题(Unable to find the requested .Net Framework Data Provider)
用entity framework 搭建的一个windows 程序,在vs中用oracle 的ODT 工具连接oracle数据库,昨天发布后出现下面一个错误, System.ArgumentExcep ...
- iOS - 网络 - NSURLSession
1.NSURLSession基础 NSURLConnection在开发中会使用的越来越少,iOS9已经将NSURLConnection废弃,现在最低版本一般适配iOS,所以也可以使用.NSURLCon ...
- 仿jQuery中undelegate()方法功能的函数
//跨浏览器事件绑定 function addEvent(obj,type,fn){ if(typeof obj.removeEventListener !='undefined'){ /////// ...