https://vjudge.net/problem/UVA-820

题意:

给出所有计算机之间的路径和路径容量后求出两个给定结点之间的流通总容量。

思路:

裸的最大流问题。注意有个比较坑的地方,最后需要多输出一个空行,否则会wa。

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstring>
  4. #include<queue>
  5. using namespace std;
  6.  
  7. const int maxn = ;
  8.  
  9. int n, m;
  10. int s, e;
  11. int G[maxn][maxn];
  12. int vis[maxn];
  13. int pre[maxn];
  14. int flow;
  15.  
  16. void Maxflow()
  17. {
  18. flow = ;
  19. for (;;)
  20. {
  21. memset(vis, , sizeof(vis));
  22. memset(pre, , sizeof(pre));
  23. queue<int> Q;
  24. Q.push(s);
  25. vis[s] = ;
  26. while (!Q.empty())
  27. {
  28. int x = Q.front();
  29. Q.pop();
  30. if (x == e) break;
  31. for (int i = ; i <= n; i++)
  32. {
  33. if (!vis[i] && G[x][i] > )
  34. {
  35. vis[i] = ;
  36. Q.push(i);
  37. pre[i] = x;
  38. }
  39. }
  40. }
  41. if (!vis[e]) break;
  42. int _min = ;
  43. for (int i = e; i != s; i = pre[i])
  44. _min = min(_min, G[pre[i]][i]);
  45. for (int i = e; i != s; i = pre[i])
  46. {
  47. G[i][pre[i]] += _min;
  48. G[pre[i]][i] -= _min;
  49. }
  50. flow += _min;
  51. }
  52. }
  53.  
  54. int main()
  55. {
  56. //freopen("D:\\txt.txt", "r", stdin);
  57. int kase = ;
  58. while (~scanf("%d",&n) && n)
  59. {
  60. memset(G, , sizeof(G));
  61. cin >> s >> e >> m;
  62. int x, y, c;
  63. for (int i = ; i < m; i++)
  64. {
  65. cin >> x >> y >> c;
  66. G[x][y] += c;
  67. G[y][x] = G[x][y]; //因为双向,所以得加上这个
  68. }
  69. Maxflow();
  70. cout << "Network " << ++kase << endl;
  71. cout << "The bandwidth is " << flow << "." << endl << endl; //坑点,多输出一个空行
  72. }
  73. }

UVa 820 因特网带宽(最大流)的更多相关文章

  1. UVA 820 --- POJ 1273 最大流

    找了好久这两个的区别...UVA820 WA了 好多次.不过以后就做模板了,可以求任意两点之间的最大流. UVA 是无向图,因此可能有重边,POJ 1273是有向图,而且是单源点求最大流,因此改模板的 ...

  2. UVA - 820 Internet Bandwidth (因特网带宽)(最大流)

    题意:给出所有计算机之间的路径和路径容量后,求出两个给定结点之间的流通总容量.(假设路径是双向的,且两方向流动的容量相同) 分析:裸最大流.标号从1开始,初始化的时候注意. #pragma comme ...

  3. UVA 820 Internet Bandwidth 因特网宽带(无向图,最大流,常规)

    题意:给一个无向图,每条边上都有容量的限制,要求求出给定起点和终点的最大流. 思路:每条无向边就得拆成2条,每条还得有反向边,所以共4条.源点汇点已经给出,所以不用建了.直接在图上跑最大流就可以了. ...

  4. uva 820(最大流)

    最大流的裸题,直接贴了模板. #include <cstdio> #include <iostream> #include <sstream> #include & ...

  5. UVA - 820 Internet Bandwidth(最大流模板题)

    题目: 思路: 直接套最大流的模板就OK了,注意一下输出的格式. 代码: #include <bits/stdc++.h> #define inf 0x3f3f3f3f #define M ...

  6. 紫书 习题 11-3 UVa 820 (最大流裸题)

    注意这道题是双向边, 然后直接套模板就ok了. #include<cstdio> #include<algorithm> #include<vector> #inc ...

  7. Risk UVA - 12264 拆点法+最大流+二分 最少流量的节点流量尽量多。

    /** 题目:Risk UVA - 12264 链接:https://vjudge.net/problem/UVA-12264 题意:给n个点的无权无向图(n<=100),每个点有一个非负数ai ...

  8. uva 1658(最小费用最大流)

    题意:一个带权有向图,求起点到终点的两条路径权值之和最小,且两条路径没有公共点(除起点,终点): 分析:拆点法,将u拆成u和u',u-u'容量为1,费用为0,这样就能保证每个点只用一次,起点s-s'容 ...

  9. UVA 10779 Collectors Problem(最大流)

    这个题是很难往网络流上面构思的... 从s向每个物品增加容量为Bob拥有数的弧,然后从每个物品向t增加容量为1的弧(代表种类个数).这时候跑最大流的话,得到的肯定是Bob拥有的初始种类数.那么交换后的 ...

随机推荐

  1. gh-ost安装

    下载 : https://github.com/github/gh-ost/releases/tag/v1.0.28 先安装Go语言: sudo yum install golang 将gh-ost文 ...

  2. HTML5-Canvas 绘制线条的深入认识

    1. lineWidth 线条宽度 ( 示例: lineWidth = 10 ) 2. lineCap 线条帽(线条两端的形状) ( 示例: lineCap = butt(default) | rou ...

  3. FPKM\RPKM\TPM学习[转载]

    转自:http://www.360doc.com/content/18/0112/02/50153987_721216719.shtml 1.问题提出 在RNA-Seq的分析中,对基因或转录本的rea ...

  4. [LeetCode] 877. Stone Game == [LintCode] 396. Coins in a Line 3_hard tag: 区间Dynamic Programming, 博弈

    Alex and Lee play a game with piles of stones.  There are an even number of piles arranged in a row, ...

  5. Lintcode: Lowest Common Ancestor

    Given the root and two nodes in a Binary Tree. Find the lowest common ancestor(LCA) of the two nodes ...

  6. Summary: Java中函数参数的传递

    函数调用参数传递类型(java)的用法介绍. java方法中传值和传引用的问题是个基本问题,但是也有很多人一时弄不清. (一)基本数据类型:传值,方法不会改变实参的值. public class Te ...

  7. Bootstrap下拉单学习

    <!DOCTYPE HTML><html><head><link rel="stylesheet" href="/stylesh ...

  8. yii2redis安装

    yii2 – redis 配置 转自:http://www.fancyecommerce.com/2016/05/03/yii2-redis-%E9%85%8D%E7%BD%AE/ 安装redis w ...

  9. Linux服务器---安装apache

    Apache安装    1.安装Apache,使用命令“yum install httpd -y” [root@localhost ~]# yum install httpd -y Loaded pl ...

  10. php array 根据value获取key,in_array()判断是否在数组内实例

    php array 根据value获取key,in_array()判断是否在数组内实例 <?php header("Content-type: text/html; charset=u ...