hdu------(3549)Flow Problem(最大流(水体))
Flow Problem
Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 8203 Accepted Submission(s): 3817
flow is a well-known difficult problem for ACMers. Given a graph, your
task is to find out the maximum flow for the weighted directed graph.
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)
3 2
1 2 1
2 3 1
3 3
1 2 1
2 3 1
1 3 1
Case 2: 2
#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
const int inf=0x3f3f3f3f;
int mat[][];
int dist[];
int n,m;
int min(int a,int b)
{
return a<b?a:b;
}
bool bfs(int st,int to){
memset(dist,-,sizeof(dist));
queue<int>q;
q.push(st);
dist[st]=;
int t;
while(!q.empty()){
t=q.front();
q.pop();
for(int i=;i<=n;i++){
if(dist[i]<&&mat[t][i]>){
dist[i]=dist[t]+;
if(i==to)return ;
q.push(i);
}
}
}
return ;
}
int dfs(int st,int to,int flow)
{
int tem;
if(st==to||flow==) return flow;
for(int i=;i<=n;i++){
if((dist[i]==dist[st]+)&&mat[st][i]>&&(tem=dfs(i,to,min(mat[st][i],flow))))
{
mat[st][i]-=tem;
mat[i][st]+=tem;
return tem;
}
}
return ;
}
int Dinic(int st,int en)
{
int ans=;
while(bfs(st,en))
ans+=dfs(st,en,inf);
return ans;
}
int main(){
int cas,i,a,b,c;
scanf("%d",&cas);
for(i=;i<=cas;i++){
scanf("%d%d",&n,&m);
memset(mat,,sizeof(mat));
while(m--){
scanf("%d%d%d",&a,&b,&c);
mat[a][b]+=c;
}
printf("Case %d: %d\n",i,Dinic(,n));
}
return ;
}
hdu------(3549)Flow Problem(最大流(水体))的更多相关文章
- hdu - 3549 Flow Problem (最大流模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=3549 Ford-Fulkerson算法. #include <iostream> #include ...
- hdu 3549 Flow Problem (最大流)
裸最大流,做模板用 m条边,n个点,求最大流 #include <iostream> #include <cstdio> #include <cstring> #i ...
- hdu 3549 Flow Problem 最大流 Dinic
题目链接 题意 裸的最大流. 学习参考 http://www.cnblogs.com/SYCstudio/p/7260613.html Code #include <bits/stdc++.h& ...
- 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
网络流 HDU 3549 Flow Problem 题目:pid=3549">http://acm.hdu.edu.cn/showproblem.php?pid=3549 用增广路算法 ...
- 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 Flow Problem Description Network flow is a well- ...
- 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 Edmonds_Karp算法求解最大流
Flow Problem 题意:N个顶点M条边,(2 <= N <= 15, 0 <= M <= 1000)问从1到N的最大流量为多少? 分析:直接使用Edmonds_Karp ...
- HDU 3549 Flow Problem 网络流(最大流) FF EK
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
随机推荐
- 逐个后移,匹配符合要求的选项,ie7有bug
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- JSON 数据解析
json解析的几种方法(将字符串解析为object对象和objectArray对象数组) 1 Android自带api 包名 org.json // json = {"school&quo ...
- SQL中添加远程服务器连接
EXEC sp_addlinkedserver 'Testserver','','SQLOLEDB','192.168.1.221' EXEC sp_addlinkedsrvlogin 'Testse ...
- Java反序列化漏洞通用利用分析
原文:http://blog.chaitin.com/2015-11-11_java_unserialize_rce/ 博主也是JAVA的,也研究安全,所以认为这个漏洞非常严重.长亭科技分析的非常细致 ...
- css 集锦。
可以是 链接的下划线 去掉. a {text-decoration: none} position:absolute 绝对定位 position:relative 相对定位 ie 图片失真 -ms ...
- Jquery基本、层次选择器
基本选择器: $("#none").css("background","#bbffaa"); 改变id为none的所有元素的背景色 $(&q ...
- 个人作业Week 2 ----------代码的规范和代码复审
1.是否需要有代码规范 从个人理解的角度出发,我认为代码规范还可以细分为代码的风格还有代码的结构设计(就好比排版一类的) 以前在上C语言课程的时候就看到过,老师会在打“{”的时候进行一个换行,但是有些 ...
- opencv 61篇
(一)--安装配置.第一个程序 标签: imagebuildincludeinputpathcmd 2011-10-21 16:16 41132人阅读 评论(50) 收藏 举报 分类: OpenCV ...
- mysql 1030 Got error 28 from storage engine
mysql 1030 Got error 28 from storage engine 错误原因:磁盘临时空间不够. 解决办法:df -h 查看设备存储的使用情况 du -h --max-depth= ...
- MFC编程入门之五(MFC消息映射机制概述)
在MFC软件开发中,界面操作或者线程之间通信都会经常用到消息,通过对消息的处理实现相应的操作.比较典型的过程是,用户操作窗口,然后有消息产生,送给窗口的消息处理函数处理,对用户的操作做出响应. 一.什 ...