poj1273 Drainage Ditches 基础网络流
#include <iostream>
#include <queue>
using namespace std;
int G[][];
int Prev[]; //路径上每个节点的前驱节点
bool Visited[];
int n,m; //m是顶点数目,顶点编号从1开始 1是源,m是汇, n是 边数 int Augment()
{
int v;
int i;
deque<int> q;
memset(Prev,,sizeof(Prev));
memset(Visited,,sizeof(Visited));
Prev[] = ;
Visited[] = ;
q.push_back();
bool bFindPath = false;
//用bfs寻找一条源到汇的可行路径
while (!q.empty())
{
v = q.front();
q.pop_front();
for (i = ; i <= m; i++)
{
if (G[v][i] > && Visited[i] == )
{
//必须是依然有容量的边,才可以走
Prev[i] = v;
Visited[i] = ;
if( i == m )
{
bFindPath = true;
q.clear();
break;
}
else
q.push_back(i);
}
}
} if (!bFindPath)
return ;
int nMinFlow = ;
v = m; //寻找源到汇路径上容量最小的边,其容量就是此次增 加的总流量
while( Prev[v] )
{
nMinFlow = min( nMinFlow,G[Prev[v]][v]);
v = Prev[v];
}
//沿此路径添加反向边,同时修改路径上每条边的容量
v = m;
while( Prev[v] )
{
G[Prev[v]][v] -= nMinFlow;
G[v][Prev[v]] += nMinFlow;
v = Prev[v];
}
return nMinFlow;
} int main()
{
while (cin >> n >> m)
{
//m是顶点数目,顶点编号从1开始
int i,j,k;
int s,e,c;
memset( G,,sizeof(G));
for( i = ;i < n;i ++ )
{
cin >> s >> e >> c;
G[s][e] += c; //两点之间可能有多条边
}
int MaxFlow = ;
int aug;
while( aug = Augment() )
MaxFlow += aug;
cout << MaxFlow << endl;
}
return ;
}
poj1273 Drainage Ditches 基础网络流的更多相关文章
- POJ1273 Drainage Ditches (网络流)
Drainage Ditches Time Limit: 1000MS Memor ...
- [Poj1273]Drainage Ditches(网络流)
Description 给图,求最大流 最大流模板题,这里用dinic Code #include <cstdio> #include <cstring> #include & ...
- poj1273 Drainage Ditches Dinic最大流
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 76000 Accepted: 2953 ...
- 【网络流】POJ1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 78671 Accepted: 3068 ...
- poj-1273 Drainage Ditches(最大流基础题)
题目链接: Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67475 Accepted ...
- poj1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 68414 Accepted: 2648 ...
- POJ 1273 Drainage Ditches(网络流,最大流)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
- HDU 1532 Drainage Ditches (网络流)
A - Drainage Ditches Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- POJ_1273 Drainage Ditches 【网络流】
一.题面 Drainage Ditches 二.分析 网络流的裸题. 1 Edmonds-Karp算法 求解网络流其实就是一个不断找增广路,然后每次找到一条增广路后更新残余网络的一个过程. EK算法主 ...
随机推荐
- 简单的dp hdu 数塔(水题)
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- Java Unit Testing - JUnit & TestNG
转自https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaUnitTesting.html yet another insignifican ...
- linux内核模块依赖图
Module Size Used by btrfs 880032 0 raid6_pq 97812 ...
- HBase在滴滴出行的应用场景和最佳实践
摘要: 主要介绍了HBase和Phoenix在滴滴内部的一些典型案例.文章已在CSDN极客头条和<程序员>杂志发表,应朋友邀请,分享到云栖社区,希望给大家带来启发和帮助. 背景 对接业务类 ...
- sqlldr的用法
在 Oracle 数据库中,我们通常在不同数据库的表间记录进行复制或迁移时会用以下几种方法: 1. A 表的记录导出为一条条分号隔开的 insert 语句,然后执行插入到 B 表中2. 建立数据库间的 ...
- codeforces 437B. The Child and Set 解题报告
题目链接:http://codeforces.com/contest/437/problem/B 题目意思:给出两个整数 sum 和 limit,问能否从1 - limit 这些数中选出一些数(注意: ...
- pyspark 日期格式
1. 获取当前日期 from pyspark.sql.functions import current_date spark.range(3).withColumn('date',current_da ...
- Java 网络处理(net io URL 等)
1. URL 类 URL 类的两个重要方法: openStream():打开到此 URL 的连接并返回一个用于从该连接读入的 InputStream. URL url = new URL(" ...
- 关于布局(Layout)的一切
之前在布局中有很多问题也有很多经验,遗憾都没记下来.现在一点点记下一些东西. 1.外层用LinearLayout的话,常常把orientation设成vertical, android:orienta ...
- NFS (网络文件系统)
NFS (网络文件系统) https://www.cnblogs.com/wahaha02/p/9559345.html Linux网络文件系统的实现与调试 NFS协议 NFS (网络文件系统)不是传 ...