HDU 3549 Flow Problem (简单最大流问题)
来源:互联网 发布:mysql自动增长赋值 编辑:程序博客网 时间:2024/06/10 08:51
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549
简单明了的最大流问题,就当熟练模板了。
记得补题解的孩子都是好孩子。
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>#define MAX 65535#define Max 10000using namespace std;struct node{ int e; int w; int fro;}eg[Max << 1];int head[Max << 1];int cont;int add(int s,int e,int w){ eg[cont].e = e; eg[cont].w = w; eg[cont].fro = head[s]; head[s] = cont++; eg[cont].e = s; eg[cont].w = 0; eg[cont].fro = head[e]; head[e] = cont++; return 0;}int dis[Max << 1];int BFS(int s,int e){ queue<int> que; int now; memset(dis,-1,sizeof (dis)); dis[s] = 0; que.push(s); while (!que.empty()) { now = que.front(); que.pop(); for (int i = head[now];i != -1;i = eg[i].fro) { int v = eg[i].e; if (dis[v] == -1 && eg[i].w > 0) { dis[v] = dis[now] + 1; que.push(v); } } } if (dis[e] != -1) return 1; return 0;}int dinic(int s,int e,int t){ if (s == e) return t; int tmp = t; for (int i = head[s];i != -1;i = eg[i].fro) { int v = eg[i].e; if (dis[v] == dis[s] +1 && eg[i].w > 0) { int imin = dinic(v,e,min(t,eg[i].w)); eg[i].w -= imin; eg[i ^ 1].w += imin; t -= imin; } } return tmp - t;}int main(){ int n,m; int N; int cas = 1; scanf ("%d",&N); while (N--) { int i,k; cont = 0; memset(head,-1,sizeof (head)); scanf ("%d%d",&n,&m); for (i = 0;i < m;i++) { int s,e,w; scanf ("%d%d%d",&s,&e,&w); add(s,e,w); } int ans = 0; while (BFS(1,n)) ans += dinic(1,n,MAX); printf ("Case %d: %d\n",cas++,ans); } return 0;}
0 0
- HDU 3549 Flow Problem (简单最大流问题)
- hdu - 3549 - Flow Problem(最大流)
- HDU 3549 Flow Problem(最大流)
- HDU 3549 Flow Problem(最大流)
- HDU 3549 Flow Problem (最大流)
- hdu 3549 Flow Problem(最大流)
- hdu 3549 Flow Problem【最大流问题】【FF】
- HDU-3549 Flow Problem【最大流】
- hdu 3549 Flow Problem【最大流】
- hdu 3549 Flow Problem 最大流
- hdu 3549 Flow Problem (最大流)
- Hdu 3549 Flow Problem - 最大流
- HDU 3549 Flow Problem 最大网络流
- hdu 3549 最大网络流 Flow Problem
- hdu 3549 Flow Problem(最大流)
- HDU 3549 Flow Problem (最大流)
- HDU 3549--Flow Problem【最大流】
- HDU 3549--Flow Problem 【最大流 && dinic】
- 得到包下所有类
- grep、cut常见用法
- oracle隔离级别
- Innodb独立的undo tablespace
- ADB 常用命令
- HDU 3549 Flow Problem (简单最大流问题)
- LVS群集汇总,实现高可用
- spring动态生成bean
- PACKET_MMAP实现原理分析
- linux设备驱动--HelloWorld
- 总结Themida / Winlicense加壳软件的脱壳方法
- JS中实现replaceAll的方法
- Permutation Sequence
- Lesson 1