Ford-Fulkerson方法入门。

有多个输入,因为这个WA了好多次。

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>using namespace std;const int MAX_N_M = 205;
const int INF = 10000005;struct edge {int to;int cap;int rev;
};int n, m;
vector<edge> G[MAX_N_M];
bool used[MAX_N_M];void add_edge(int from, int to, int cap) {   //重边不影响 G[from].push_back((edge){to, cap, G[to].size()});G[to].push_back((edge){from, 0, G[from].size()-1});
}int dfs(int v, int t, int f) {if(v == t) return f;used[v] = true;for(int i=0; i<G[v].size(); i++) {edge &e = G[v][i];if(!used[e.to] && e.cap>0) {int d = dfs(e.to, t, min(f, e.cap));if(d > 0) {e.cap -= d;G[e.to][e.rev].cap += d;return d;}}}return 0;
}int max_flow(int s, int t) {int flow = 0;while(true) {memset(used, 0, sizeof(used));int f = dfs(s, t, INF);if(f == 0)  return flow;flow += f;}
}int main() {while(~scanf("%d%d", &n, &m)) {memset(G, 0, sizeof(G));  //G需要初始化 for(int i=0; i<n; i++) {int a, b, c;scanf("%d%d%d", &a, &b, &c);add_edge(a, b, c);}printf("%d\n", max_flow(1, m));   }return 0;
}

hduoj 1532相关推荐

  1. HDUOJ 1060 Leftmost Digit

    问题:求x^x的最高位 思路: 假设a = x^x,对10求对数有log(a) = x * log(x) = b.cd,其中b表示指数的最大表示,10^(.cd)就是底 具体代码参考: https:/ ...

  2. 【矩阵乘法】递推(ssl 1532)

    递推 ssl 1532 题目大意 给出数列a0,a1-ana_0,a_1-a_na0​,a1​-an​和fff的前n−1n-1n−1项f0,f1-fn−1f_0,f_1-f_{n-1}f0​,f1​- ...

  3. HDUOJ 2059 龟兔赛跑——

    HDUOJ 2059 龟兔赛跑 Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击――赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终 ...

  4. HDUOJ 1847 Good Luck in CET-4 Everybody!

    HDUOJ 1847 Good Luck in CET-4 Everybody! Problem Description 大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都 ...

  5. HDUOJ 4513 吉哥系列故事——完美队形II

    HDUOJ 4513 吉哥系列故事--完美队形II Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] - ...

  6. HDUOJ 1069 Monkey and Banana

    HDUOJ 1069 Monkey and Banana 题目链接 Problem Description A group of researchers are designing an experi ...

  7. HDUOJ 6441 Find Integer

    HDUOJ 6441 Find Integer 题目链接 Problem Description people in USSS love math very much, and there is a ...

  8. HDUOJ 2859 Phalanx

    HDUOJ 2859 Phalanx 题目链接 Problem Description Today is army day, but the servicemen are busy with the ...

  9. HDUOJ 6608 Fansblog

    HDUOJ 6608 Fansblog 题目链接 Problem Description Farmer John keeps a website called 'FansBlog' .Everyday ...

  10. HDUOJ 2955 Robberies

    HDUOJ 2955 Robberies 题目链接 Problem Description The aspiring Roy the Robber has seen a lot of American ...

最新文章

  1. 局域网怎样自动安装FLASH插件(浏览器不安装flashplayer都可以浏览.swf文件)
  2. debian+pxe+preseed.cfg 安装配置
  3. 电子工程师必须知道的10个网站 !!!
  4. 多分辨率适配—字体大小适配 sp与dp区别
  5. LeetCode Maximum XOR of Two Numbers in an Array(贪心、字典树)
  6. 线程安全退出 VS PostMessage,SendMessage的区别
  7. 《The Art of Readable Code》学习笔记(一)
  8. MySQL查询select实例 【笔记】
  9. JEECG社区 一个微信教育网站案例源码分享
  10. Google 地图 google map api / 地图有关
  11. kafka 消费者消息确认_Kafka整体架构图解
  12. MacOS开发必备工具brew,安装nginx反向代理,替代linux工具 apt-get和 yum
  13. 86 arduino 电机yl_Arduino 直流电机
  14. i8一点通如何加载虚拟光驱玩游戏
  15. Markdown - CSND
  16. 推荐系统论文阅读:Entire Space Multi-Task Model
  17. C#中的控件Binding
  18. MySQL数据库——锁机制
  19. 白苹果了怎么办_iOS 13如何降级?iOS13降级失败怎么办?
  20. 解决Field ‘id‘ doesn‘t have a default value 问题

热门文章

  1. 设置vim默认显示行号
  2. WPF:MVVM模式下ViewModel关闭View
  3. TCP/UDP-路由交换原理6-【HCNA笔记】
  4. Socket Tcp高密集信息广播转发强度测试
  5. CHARINDEX 连同 SUBSTRING 对字符串删除处理...
  6. vi单文件操作常用命令
  7. js base64图片太大_手把手教你常用JS方法封装(一) [ 大杂烩 ]
  8. python 无限循环小程序设计_Python如何实现小程序 无限求和平均
  9. PAT之算法/技巧:01背包
  10. iPhone清理喇叭灰尘_厉害了!原来可以这样一键清理 iPhone 喇叭灰尘!