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 ...
随机推荐
- Shell脚本中的交互式命令处理
先贴代码: DATE=`date -d -1hour +%T` fileName=erver_`date -d now +%Y-%m-%d-%H%M%S`.txt cp /home/BLload_ba ...
- Java自制人机小游戏——————————剪刀、石头、布
package com.hello.test; import java.util.Scanner; public class TestGame { public static void main(St ...
- 数据引用Data References
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- FZU 2105 Digits Count(位数计算)
Description 题目描述 Given N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations: Operation ...
- .net 常用Response.ContentType
来源:http://blog.csdn.net/navy235/article/details/5982319 不同的ContentType 会影响客户端所看到的效果.默认的ContentType为 ...
- Windows Internals学习笔记(五)Synchronization
参考资料: 1. <Windows Internals> 2. 自旋锁spinlock剖析与改进 3. Lock指令前缀 4. Lock指令前缀(二) 5. Kernel Dispatch ...
- 图-用DFS求连通块- UVa 1103和用BFS求最短路-UVa816。
这道题目甚长, 代码也是甚长, 但是思路却不是太难.然而有好多代码实现的细节, 确是十分的巧妙. 对代码阅读能力, 代码理解能力, 代码实现能力, 代码实现技巧, DFS方法都大有裨益, 敬请有兴趣者 ...
- XAF Excel数据导入模块使用说明与源码
我实现了XAF项目中Excel数据的导入,使用Devexpress 新出的spreadsheet控件,可能也不新了吧:D 好,先看一下效果图:下图是Web版本的. 下面是win版: 功能说明: 支持从 ...
- jquery使用技巧
1. 禁用右键点击(Disable right-click) <!DOCTYPE html> <html> <head> <meta charset=&quo ...
- poj1755Triathlon(半平面交)
链接 根据题意可以设三段路程分别为A,B,C 那么总时间t = A/V+B/U+C/W. 这样根据时间大小关系可以跟其余n-1个联立形成n-1个方程. 化简后为A(1/vj-1/vi)+B(1/uj- ...