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 ...
随机推荐
- linux系统莫名被黑的诡异经历
2017年10月28日,ssh登录本地虚拟机之后发现主机名被改成了HUAIWEI_P10. 我一个同事用的此款手机,起初怀疑是他,没放心上. 今天(10月30)发现自己ssh登录不上了.恼火了办公室开 ...
- Jenkins集成taffy进行自动化测试并输出测试报告
本文主要介绍Jenkins集成taffy/nose框架进行自动化测试并输出测试报告方法. 0. 测试环境 Jenkis主节点部署在CentOS系统上,子节点为Win10 64位系统(即我们本机运行自动 ...
- Java基础笔记6
OOP(Object Oriented Programmer) 面向对象编程 面向对象编程的语言:JAVA,C#,PHP,ASP 用途:把现实中的任何对象描述成java语言. java面向对象 ...
- shuffle过程简介--笔记
数据保存在hdfs上 拿到数据后分片处理 输入到Map 输出键值对 写到缓存,满的时候溢写到磁盘 缓存的数据写入磁盘的过程中,分区排序,合并 多个磁盘文件归并 通知Reduce任务拉取 Map端的sh ...
- HDFS的接口(命令行接口和Java接口)--笔记
HDFS 文件的系统访问的接口 1.Hadoop的shell命令脚本 hadoop fs -ls 列出某一个目录下的文件 hadoop fs -lsr 递归的方式列出所有文件 hadoop fs ...
- ajax请求发送和页面跳转的冲突
http://blog.csdn.net/allenliu6/article/details/77341538?locationNum=7&fps=1 在A页面中,有一个click事件,点击时 ...
- 可点击的icon按钮 无障碍 ARIA 可访问性
最简单: <input type="image" src="email.png" width="14" height="14 ...
- scala读取parquet文件
import org.apache.spark.SparkConfimport org.apache.spark.SparkContextimport org.apache.spark.sql.SQL ...
- Maven 编译错误 Dynamic Web Module 3.0 requires Java 1.6 or newer 解决方案
Eclipse Maven 开发一个 jee 项目时,编译时遇到以下错误:Description Resource Path Location TypeDynamic Web Module 3.0 r ...
- centos7.2构建Python3.5开发环境
1.本次使用的是一台全新的腾讯云主机,首先获取linux系统版本信息. [root@VM_46_121_centos ~]# cat /etc/redhat-release <本系统默认自带py ...