hdu 3549 Flow Problem 【最大流】
其实还是不是很懂dinic-----
抄了一个模板---
http://www.cnblogs.com/naturepengchen/articles/4403408.html
先放在这里~~~
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std; const int maxn = ;
const int INF = ( << ) - ; struct Edge{
int v,next,c;
}e[maxn]; int st,ed,lev[maxn],first[maxn],now[maxn],ecnt;
int n,m; void init(int a,int b){
st = a; ed = b;
memset(first,-,sizeof(first));
ecnt = ;
} void addedges(int u,int v,int c){
e[ecnt].next = first[u];
e[ecnt].v = v;
e[ecnt].c = c;
first[u] = ecnt++; e[ecnt].next = first[v];
e[ecnt].v = u;
e[ecnt].c = ;
first[v] = ecnt++;
} bool bfs(){
queue<int> q;
while(!q.empty()) q.pop();
q.push(st);
memset(lev,-,sizeof(lev));
lev[st] = ;
while(!q.empty()){
int x = q.front();q.pop();
for(int i = first[x];~i;i = e[i].next){
int v = e[i].v;
if(lev[v] < && e[i].c > ){
lev[v] = lev[x] + ;
q.push(v);
}
}
}
return lev[ed] != -;
} int dfs(int p,int minf){
if(p == ed || minf == ) return minf;
for(int &i = now[p];~i;i = e[i].next){
int v = e[i].v;
if(lev[v] == lev[p] + && e[i].c > ){
int d = dfs(v,min(e[i].c,minf));
if(d > ){
e[i].c -= d;
e[i^].c += d;
return d;
}
}
}
return ;
} int dinic(){
int max_flow = ,p1;
while(bfs()){
memcpy(now,first,sizeof(first));
while((p1 = dfs(st,INF)) > )
max_flow += p1;
}
return max_flow;
} int main(){
int T;
int kase = ;
scanf("%d",&T);
while(T--){
scanf("%d %d",&n,&m);
init(,n);
for(int i = ;i < m;i++){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
addedges(a,b,c);
}
printf("Case %d: %d\n",++kase,dinic());
}
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 ...
随机推荐
- 铁大FaceBook的使用体验
铁大FaceBook是一个类似QQ和微信等聊天程序的缩小版网站,并且其针对领域较为狭窄:即只针对校园的学生和导员等人员.但其有值得推广的潜力性和可能性. 对于使用它的体验:第一点我感觉这个网站的界面很 ...
- Centos 搭建activemq
Centos 搭建activemq 1,官方下载 http://activemq.apache.org/activemq-5122-release.html apache-activemq-5.15 ...
- Project Euler 27 Quadratic primes( 米勒测试 + 推导性质 )
题意: 欧拉发现了这个著名的二次多项式: f(n) = n2 + n + 41 对于连续的整数n从0到39,这个二次多项式生成了40个素数.然而,当n = 40时402 + 40 + 41 = 40( ...
- nyoj212-k尾相等数
212-K尾相等数 内存限制:64MB时间限制:3000msSpecial Judge: No accepted:0submit:0 题目描述: 输入一个自然数K(K>1),如果存在自然数M和N ...
- 3.1、Jinja2模板引擎
形式最简单的 Jinja2 模板就是一个包含响应文本的文件.示例 3-1 是一个 Jinja2 模板,它和示例 2-1 中 index() 视图函数的响应一样. 示例 3-1 templates/in ...
- Tensorboard服务激活
首先确定Tensorflow的具体位置(在Dos环境下,也就是cmd) cd .. cd scripts conda env list activate tensorflow tensorboard ...
- keepalived安装实现nginx主备高可用
. keepalived安装环境 su - root yum -y install kernel-devel* yum -y install openssl-* yum -y install popt ...
- SpringMVC-HandlerMapping和HandlerAdapter
网上介绍HandlerMapping和HandlerAdapter的文章很多,今天我用自己的理解和语言来介绍下HandlerMapping和HandlerAdapter 一. HandlerMappi ...
- CodeForcesGym 100641D Generalized Roman Numerals
Generalized Roman Numerals Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on ...
- JavaSript 基础学习笔记
1. 数组 对象数组 var temp = [{"name":"123","age":"18"},{"name ...