UVA - 820 Internet Bandwidth (因特网带宽)(最大流)
题意:给出所有计算机之间的路径和路径容量后,求出两个给定结点之间的流通总容量。(假设路径是双向的,且两方向流动的容量相同)
分析:裸最大流。标号从1开始,初始化的时候注意。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;
struct Edge{
int from, to, cap, flow;
Edge(int fr, int t, int c, int fl):from(fr), to(t), cap(c), flow(fl){}
};
struct Dinic{
int n, m, s, t;
vector<Edge> edges;
vector<int> G[MAXN];
bool vis[MAXN];
int d[MAXN];
int cur[MAXN];
void init(int n){
edges.clear();
for(int i = 1; i <= n; ++i) G[i].clear();//标号从1开始
}
void AddEdge(int from, int to, int cap){
edges.push_back(Edge(from, to, cap, 0));
edges.push_back(Edge(to, from, 0, 0));
m = edges.size();
G[from].push_back(m - 2);
G[to].push_back(m - 1);
}
bool BFS(){
memset(vis, 0, sizeof vis);
queue<int> Q;
Q.push(s);
d[s] = 0;
vis[s] = 1;
while(!Q.empty()){
int x = Q.front();
Q.pop();
for(int i = 0; i < G[x].size(); ++i){
Edge& e = edges[G[x][i]];
if(!vis[e.to] && e.cap > e.flow){
vis[e.to] = 1;
d[e.to] = d[x] + 1;
Q.push(e.to);
}
}
}
return vis[t];
}
int DFS(int x, int a){
if(x == t || a == 0) return a;
int flow = 0, f;
for(int& i = cur[x]; i < G[x].size(); ++i){
Edge& e = edges[G[x][i]];
if(d[x] + 1 == d[e.to] && (f = DFS(e.to, Min(a, e.cap - e.flow))) > 0){
e.flow += f;
edges[G[x][i] ^ 1].flow -= f;
flow += f;
a -= f;
if(a == 0) break;
}
}
return flow;
}
int Maxflow(int s, int t){
this -> s = s;
this -> t = t;
int flow = 0;
while(BFS()){
memset(cur, 0, sizeof cur);
flow += DFS(s, INT_INF);
}
return flow;
}
}di;
int main(){
int n;
int kase = 0;
while(scanf("%d", &n) == 1){
if(!n) return 0;
di.init(n);
int s, t, c;
scanf("%d%d%d", &s, &t, &c);
for(int i = 0; i < c; ++i){
int x, y, v;
scanf("%d%d%d", &x, &y, &v);
di.AddEdge(x, y, v);//路径双向
di.AddEdge(y, x, v);
}
printf("Network %d\nThe bandwidth is %d.\n\n", ++kase, di.Maxflow(s, t));
}
return 0;
}
UVA - 820 Internet Bandwidth (因特网带宽)(最大流)的更多相关文章
- UVA 820 Internet Bandwidth 因特网宽带(无向图,最大流,常规)
题意:给一个无向图,每条边上都有容量的限制,要求求出给定起点和终点的最大流. 思路:每条无向边就得拆成2条,每条还得有反向边,所以共4条.源点汇点已经给出,所以不用建了.直接在图上跑最大流就可以了. ...
- UVA - 820 Internet Bandwidth(最大流模板题)
题目: 思路: 直接套最大流的模板就OK了,注意一下输出的格式. 代码: #include <bits/stdc++.h> #define inf 0x3f3f3f3f #define M ...
- UVa 820 Internet Bandwidth (裸板网络流)
题意:有一个计算机网络,输入节点数n,输入网络流源点和汇点src,des,再输入双向边数m.给出m条边的负载,求最大流. 析:直接上网络流的最大流. 代码如下: #pragma comment(lin ...
- UVA 820 Internet Bandwidth
题意: 给出双向图,求给出两点的流通总流量. 分析: 网络流中的增广路算法. 代码: #include <iostream>#include <cstring>#include ...
- UVA 820 --- POJ 1273 最大流
找了好久这两个的区别...UVA820 WA了 好多次.不过以后就做模板了,可以求任意两点之间的最大流. UVA 是无向图,因此可能有重边,POJ 1273是有向图,而且是单源点求最大流,因此改模板的 ...
- UVA 10480 Sabotage (网络流,最大流,最小割)
UVA 10480 Sabotage (网络流,最大流,最小割) Description The regime of a small but wealthy dictatorship has been ...
- light oj 1153 - Internet Bandwidth【网络流无向图】
1153 - Internet Bandwidth PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
- Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负
/** 题目:Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负 链接:https://vjudge.net/problem/UVA-1161 ...
- UVa 820 因特网带宽(最大流)
https://vjudge.net/problem/UVA-820 题意: 给出所有计算机之间的路径和路径容量后求出两个给定结点之间的流通总容量. 思路: 裸的最大流问题.注意有个比较坑的地方,最后 ...
随机推荐
- kafka在zookeeper默认使用/为根目录,将/更换为/kafka
需求:kafka在zookeeper默认使用/为根目录,将/更换为/kafka 步骤:1.进入kafka的根目录: [root@node01 kafka_2.11-1.0.0]# cd /export ...
- 第1节 storm日志告警:1、 - 5、日志监控告警业务需求、代码、集群运行、总结
如何解决短信或者邮件频繁发送的问题:每次发送的时候都先查询数据库记录,看一下有没有给这个人发送消息,上一次发送消息的时间是什么时候,如果发送时间间隔小于半个小时,就不要再发了 ============ ...
- 契约精神、尊重规则、SOP,对制造业来说是蜜糖还是毒药?
契约精神.尊重规则.执行SOP,这些词儿都天然带有光环,也有很多相关的好故事,全球范围内的企业家都对其推崇备至,摆出一副虔诚教徒的模样,事实上,缺乏契约精神.不遵守规则比之缺乏资本.丢掉订单更加不可接 ...
- English-Names
English-Names 1. 西方姓名的组成 2. 职业姓氏 3. 更多相关链接 中国的姓名,姓氏在前,名子在后.传统也有中间字(世代字).名子非常多.所谓百家姓,姓氏数量有限,约500个左右. ...
- Maven:sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
还是记录使用 maven 时遇到的问题. 一.maven报错 maven package 进行打包时出现了以下报错: Non-resolvable parent POM for com.wpbxin: ...
- SpringBoot开发环境要求
JDK 截止到目前Spring Boot 的最新版本:2.1.8.RELEASE 要求 JDK 版本在 1.8 以上,所以确保你的电脑已经正确下载安装配置了 JDK(推荐 JDK 1.8 版本). 构 ...
- 必应壁纸php获取接口
<?php if($_GET['idx']==null){ $str=file_get_contents('http://cn.bing.com/HPImageArchive.aspx?idx= ...
- SSH框架系列:Spring配置多个数据源
分类: [java]2013-12-09 16:59 1247人阅读 评论(0) 收藏 举报 1.问题的引入 对于普通的SSH框架而言,一般配置一个数据源,一个SessionFactory,一个事务管 ...
- arm linux 移植 python3.6
背景: 人生苦短,我用Python. 说明: 编译Python的嵌入式版需要解释器解析setup.py从而编译Python的模块,因此需要先编译出host的解释器.(有点像Go语言) Python : ...
- vue 路由过渡效果(1)
1.html界面 <transition name="slide"> <router-view></router-view> </tran ...