UVa 820 因特网带宽(最大流)
https://vjudge.net/problem/UVA-820
题意:
给出所有计算机之间的路径和路径容量后求出两个给定结点之间的流通总容量。
思路:
裸的最大流问题。注意有个比较坑的地方,最后需要多输出一个空行,否则会wa。
- #include<iostream>
- #include<algorithm>
- #include<cstring>
- #include<queue>
- using namespace std;
- const int maxn = ;
- int n, m;
- int s, e;
- int G[maxn][maxn];
- int vis[maxn];
- int pre[maxn];
- int flow;
- void Maxflow()
- {
- flow = ;
- for (;;)
- {
- memset(vis, , sizeof(vis));
- memset(pre, , sizeof(pre));
- queue<int> Q;
- Q.push(s);
- vis[s] = ;
- while (!Q.empty())
- {
- int x = Q.front();
- Q.pop();
- if (x == e) break;
- for (int i = ; i <= n; i++)
- {
- if (!vis[i] && G[x][i] > )
- {
- vis[i] = ;
- Q.push(i);
- pre[i] = x;
- }
- }
- }
- if (!vis[e]) break;
- int _min = ;
- for (int i = e; i != s; i = pre[i])
- _min = min(_min, G[pre[i]][i]);
- for (int i = e; i != s; i = pre[i])
- {
- G[i][pre[i]] += _min;
- G[pre[i]][i] -= _min;
- }
- flow += _min;
- }
- }
- int main()
- {
- //freopen("D:\\txt.txt", "r", stdin);
- int kase = ;
- while (~scanf("%d",&n) && n)
- {
- memset(G, , sizeof(G));
- cin >> s >> e >> m;
- int x, y, c;
- for (int i = ; i < m; i++)
- {
- cin >> x >> y >> c;
- G[x][y] += c;
- G[y][x] = G[x][y]; //因为双向,所以得加上这个
- }
- Maxflow();
- cout << "Network " << ++kase << endl;
- cout << "The bandwidth is " << flow << "." << endl << endl; //坑点,多输出一个空行
- }
- }
UVa 820 因特网带宽(最大流)的更多相关文章
- UVA 820 --- POJ 1273 最大流
找了好久这两个的区别...UVA820 WA了 好多次.不过以后就做模板了,可以求任意两点之间的最大流. UVA 是无向图,因此可能有重边,POJ 1273是有向图,而且是单源点求最大流,因此改模板的 ...
- UVA - 820 Internet Bandwidth (因特网带宽)(最大流)
题意:给出所有计算机之间的路径和路径容量后,求出两个给定结点之间的流通总容量.(假设路径是双向的,且两方向流动的容量相同) 分析:裸最大流.标号从1开始,初始化的时候注意. #pragma comme ...
- UVA 820 Internet Bandwidth 因特网宽带(无向图,最大流,常规)
题意:给一个无向图,每条边上都有容量的限制,要求求出给定起点和终点的最大流. 思路:每条无向边就得拆成2条,每条还得有反向边,所以共4条.源点汇点已经给出,所以不用建了.直接在图上跑最大流就可以了. ...
- uva 820(最大流)
最大流的裸题,直接贴了模板. #include <cstdio> #include <iostream> #include <sstream> #include & ...
- UVA - 820 Internet Bandwidth(最大流模板题)
题目: 思路: 直接套最大流的模板就OK了,注意一下输出的格式. 代码: #include <bits/stdc++.h> #define inf 0x3f3f3f3f #define M ...
- 紫书 习题 11-3 UVa 820 (最大流裸题)
注意这道题是双向边, 然后直接套模板就ok了. #include<cstdio> #include<algorithm> #include<vector> #inc ...
- Risk UVA - 12264 拆点法+最大流+二分 最少流量的节点流量尽量多。
/** 题目:Risk UVA - 12264 链接:https://vjudge.net/problem/UVA-12264 题意:给n个点的无权无向图(n<=100),每个点有一个非负数ai ...
- uva 1658(最小费用最大流)
题意:一个带权有向图,求起点到终点的两条路径权值之和最小,且两条路径没有公共点(除起点,终点): 分析:拆点法,将u拆成u和u',u-u'容量为1,费用为0,这样就能保证每个点只用一次,起点s-s'容 ...
- UVA 10779 Collectors Problem(最大流)
这个题是很难往网络流上面构思的... 从s向每个物品增加容量为Bob拥有数的弧,然后从每个物品向t增加容量为1的弧(代表种类个数).这时候跑最大流的话,得到的肯定是Bob拥有的初始种类数.那么交换后的 ...
随机推荐
- gh-ost安装
下载 : https://github.com/github/gh-ost/releases/tag/v1.0.28 先安装Go语言: sudo yum install golang 将gh-ost文 ...
- HTML5-Canvas 绘制线条的深入认识
1. lineWidth 线条宽度 ( 示例: lineWidth = 10 ) 2. lineCap 线条帽(线条两端的形状) ( 示例: lineCap = butt(default) | rou ...
- FPKM\RPKM\TPM学习[转载]
转自:http://www.360doc.com/content/18/0112/02/50153987_721216719.shtml 1.问题提出 在RNA-Seq的分析中,对基因或转录本的rea ...
- [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, ...
- Lintcode: Lowest Common Ancestor
Given the root and two nodes in a Binary Tree. Find the lowest common ancestor(LCA) of the two nodes ...
- Summary: Java中函数参数的传递
函数调用参数传递类型(java)的用法介绍. java方法中传值和传引用的问题是个基本问题,但是也有很多人一时弄不清. (一)基本数据类型:传值,方法不会改变实参的值. public class Te ...
- Bootstrap下拉单学习
<!DOCTYPE HTML><html><head><link rel="stylesheet" href="/stylesh ...
- yii2redis安装
yii2 – redis 配置 转自:http://www.fancyecommerce.com/2016/05/03/yii2-redis-%E9%85%8D%E7%BD%AE/ 安装redis w ...
- Linux服务器---安装apache
Apache安装 1.安装Apache,使用命令“yum install httpd -y” [root@localhost ~]# yum install httpd -y Loaded pl ...
- php array 根据value获取key,in_array()判断是否在数组内实例
php array 根据value获取key,in_array()判断是否在数组内实例 <?php header("Content-type: text/html; charset=u ...