HDU 3549 Flow Problem 网络流(最大流) FF EK
Flow Problem
Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 15345 Accepted Submission(s): 7234
For each test case, the first line contains two integers N and M, denoting the number of vertexes and edges in the graph. (2 <= N <= 15, 0 <= M <= 1000)
Next M lines, each line contains three integers X, Y and C, there is an edge from X to Y and the capacity of it is C. (1 <= X, Y <= N, 1 <= C <= 1000)
2
3 2
1 2 1
2 3 1
3 3
1 2 1
2 3 1
1 3 1
Case 1: 1
Case 2: 2
//网络流:福特-富尔克森算法(二维数组版本)
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=1e3+5;
int v;
int capacity[maxn][maxn],flow[maxn][maxn];
//capacity保存u到v的容量,flow保存u到v的流量,反方向时为负
//函数计算返回总流量
int networkflow(int source, int sink) {
memset(flow,0,sizeof(flow));
int totalflow=0;
while(true) {
//BFS寻找增广路径
vector<int> parent(maxn,-1);
queue<int> q;
parent[source]=source;
q.push(source);
while(!q.empty()) {
int here=q.front();q.pop();
for(int there=0;there<v;++there)
//沿着还有剩余容量的边搜索
if(capacity[here][there]-flow[here][there]>0&&parent[there]==-1) {
q.push(there);
parent[there]=here;
}
}
//没有增广路经存在
if(parent[sink]==-1) break;
int amount=INF;
for(int p=sink;p!=source;p=parent[p]) {
amount=min(capacity[parent[p]][p]-flow[parent[p]][p],amount);
}
//决定通过增广路径传输流
for(int p=sink;p!=source;p=parent[p]) {
flow[parent[p]][p]+=amount;
flow[p][parent[p]]-=amount;
}
totalflow+=amount;
}
return totalflow;
}
int main() {
int t,cnt=1;
scanf("%d",&t);
while(t--) {
int n,m;
scanf("%d%d",&n,&m);
v=n;
memset(capacity,0,sizeof(capacity));
for(int i=0;i<m;++i) {
int x,y,c;
scanf("%d%d%d",&x,&y,&c);
capacity[x-1][y-1]+=c;
}
printf("Case %d: %d\n",cnt++,networkflow(0,n-1));
}
return 0;
}
HDU 3549 Flow Problem 网络流(最大流) FF EK的更多相关文章
- HDU 3549 Flow Problem(最大流)
HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- hdu 3549 Flow Problem【最大流增广路入门模板题】
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Time Limit: 5000/5000 MS (Java/Others ...
- HDU 3549 Flow Problem(最大流模板)
http://acm.hdu.edu.cn/showproblem.php?pid=3549 刚接触网络流,感觉有点难啊,只好先拿几道基础的模板题来练练手. 最大流的模板题. #include< ...
- HDU 3549 Flow Problem (最大流ISAP)
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tota ...
- hdu 3549 Flow Problem (网络最大流)
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tota ...
- hdu 3549 Flow Problem 网络流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Network flow is a well-known difficult problem f ...
- hdu 3549 Flow Problem(最大流模板题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Problem Description Network flow is a well-known ...
- 题解报告:hdu 3549 Flow Problem(最大流入门)
Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph, your t ...
- hdu 3549 Flow Problem 【最大流】
其实还是不是很懂dinic----- 抄了一个模板--- http://www.cnblogs.com/naturepengchen/articles/4403408.html 先放在这里--- #i ...
随机推荐
- Asp.net Api中使用OAuth2.0实现“客户端验证”
一.实现继承自OAuthAuthorizationServerProvider的类,实现以"客户端验证"方式传入的相关认证和access_token发放. public class ...
- Java基础笔记10
类的设计分析: 1.根据需求抽取属性.(名词几乎都是属性) 2.属性私有化(private) 3.生成setter和getter方法 4.可以根据需要添加构造函数. 5.根据需求抽取其他方法.(动词几 ...
- 聊聊java基础,int值强制类型转换成byte
聊聊java基础,int值强制类型转换成byte 知识点:byte.short.char在表达式中会自动提升为int 之前做一个应用时,打印IP地址,因为是用4个byte存储的,所以打印的时候值范围是 ...
- AJAX,PHP,前端简单交互制作输入框效果
PHP数据 <?php // 数据 $arr = array( array("百度", "http://www.baidu.com/"), array(& ...
- JavaNIO缓冲区
package com.nio.test; import java.nio.ByteBuffer; import org.junit.Test; /** * * @author fliay * * 一 ...
- node调试工具--node-inspector安装
node-inspector安装: npm install --registry=http://r.cnpmjs.org -g cnpm cnpm install -g node-inspector ...
- 移动端click事件延迟300ms的原因以及解决办法[转载]
原文:http://www.bubuko.com/infodetail-822565.html 这要追溯至 2007 年初.苹果公司在发布首款 iPhone 前夕,遇到一个问题 —— 当时的网站都是为 ...
- linux tar命令 压缩、打包、解压 详解
linux tar命令 压缩.打包.解压 详解 1.常用压缩命令 tar –czvf 压缩后的文件.tar.gz 要压缩的文件 2.常用解压命令 tar –xzvf 解压后的文件.tar.gz [要解 ...
- params修饰符
http://msdn.microsoft.com/zh-cn/library/w5zay9db.aspx params 关键字可以指定采用数目可变的参数的方法参数. 可以发送参数声明中所指定类型的逗 ...
- C#中简单的this与get的用法(string,decimal)
代码 namespace First{publicpartialclass Form1 : Form{public Form1(){InitializeComponent();} privatevoi ...