Description

CIA headquarter collects data from across the country through its classified network. They have been using optical fibres long before it's been deployed on any civilian projects. However they are still under a lot pressure recently because the data are growing rapidly. As a result they are considering upgrading the network with new technologies that provide a few times wider bandwidth. In the experiemental stage, they would like to upgrade one segment of their original network in order to see how it performs. And as a CIA intern it's your responsibility to investigate which segment could actually help increase the total bandwidth the headquarter receives, suppose that all the cities have infinite data to send and the routing algorithm is optimized. As they have prepared the data for you in a few minutes, you are told that they need the result immediately. Well, practically immediately.

Input

Input contains multiple test cases. First line of each test case contains three integers n, m and l, they represent the number of cities, the number of relay stations and the number of segments. Cities will be referred to as integers from 1 to n, while relay stations use integers from n+1 to n+m. You can saves assume that n + m <= 100, l <= 1000 (all of them are positive). The headquarter is identified by the integer 0.

The next l lines hold a segment on each line in the form of a b c, where a is the source node and b is the target node, while c is its bandwidth. They are all integers where a and b are valid identifiers (from 0 to n+m). c is positive. For some reason the data links are all directional.

The input is terminated by a test case with n = 0. You can safely assume that your calculation can be housed within 32-bit integers.

Output

For each test print the segment id's that meets the criteria. The result is printed in a single line and sorted in ascending order, with a single space as the separator. If none of the segment meets the criteria, just print an empty line. The segment id is 1 based not 0 based.

题目大意:有n个发射点,m个中间点,和一个接受点0,中间由L条有向光纤连接,每个光纤有一定的带宽,问扩大哪些光纤(只能扩大一条)的带宽可以扩大发射点的总带宽。

思路:从源点S到n个发射点连一条容量为无穷大的边,再连接L条光纤,容量为该光纤的带宽,以0为汇点T。题目转化成扩大哪些边的容量可以增加最大流。先在图上求最大流,在残量网络中,把S能到的点标记为1,把能到T的点标记为2,那么当一条边的出发点为1、结束点为2,这条边就是关键割边,也就是所求的边之一。如果有一条边的其中一个点未被标记,那么扩大这条边的容量,也就不过是从源点到达的点多了一个,或者到达汇点的点多了一个,但是在这个残量网络中依旧没有从S到T的增广路。如果两个点都未被标记……那更加不可以啦……

PS:出发点为2结束点为1的边,增加容量也不会有增广路出现,曾因为这个WA了一次>_<

BFS+ISAP(30MS):

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std; const int MAXN = ;
const int MAXE = ;
const int INF = 0x3fff3fff; struct SAP {
int head[MAXN], dis[MAXN], pre[MAXN], cur[MAXN], gap[MAXN];
int to[MAXE], next[MAXE], flow[MAXE];
int n, st, ed, ecnt; void init() {
memset(head, , sizeof(head));
ecnt = ;
} void add_edge(int u, int v, int c) {
to[ecnt] = v; flow[ecnt] = c; next[ecnt] = head[u]; head[u] = ecnt++;
to[ecnt] = u; flow[ecnt] = ; next[ecnt] = head[v]; head[v] = ecnt++;
//printf("%d->%d flow = %d\n", u, v, c);
} void bfs() {
memset(dis, 0x3f, sizeof(dis));
queue<int> que; que.push(ed);
dis[ed] = ;
while(!que.empty()) {
int u = que.front(); que.pop();
++gap[dis[u]];
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
if(flow[p ^ ] && dis[v] > n) {
dis[v] = dis[u] + ;
que.push(v);
}
}
}
} int Max_flow(int ss, int tt, int nn) {
st = ss; ed = tt; n = nn;
int ans = , minFlow = INF, u;
for(int i = ; i <= n; ++i) {
cur[i] = head[i];
gap[i] = ;
}
u = pre[st] = st;
bfs();
while(dis[st] < n) {
bool flag = false;
for(int &p = cur[u]; p; p = next[p]) {
int &v = to[p];
if(flow[p] && dis[u] == dis[v] + ) {
flag = true;
minFlow = min(minFlow, flow[p]);
pre[v] = u;
u = v;
if(u == ed) {
ans += minFlow;
while(u != st) {
u = pre[u];
flow[cur[u]] -= minFlow;
flow[cur[u] ^ ] += minFlow;
}
minFlow = INF;
}
break;
}
}
if(flag) continue;
int minDis = n - ;
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
if(flow[p] && minDis > dis[v]) {
minDis = dis[v];
cur[u] = p;
}
}
if(--gap[dis[u]] == ) break;
gap[dis[u] = minDis + ]++;
u = pre[u];
}
return ans;
} int mark[MAXN]; void make_cut() {
memset(mark, , sizeof(mark));
queue<int> que;
que.push(st); mark[st] = ;
while(!que.empty()) {
int u = que.front(); que.pop();
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
if(flow[p] && !mark[v]) {
mark[v] = ;
que.push(v);
}
}
}
que.push(ed); mark[ed] = ;
while(!que.empty()) {
int u = que.front(); que.pop();
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
if(flow[p ^ ] && !mark[v]) {
mark[v] = ;
que.push(v);
}
}
}
}
} G; int from[MAXE], to[MAXE];
int n, m, L, c; int main() {
while(scanf("%d%d%d", &n, &m, &L) != EOF) {
if(n == ) break;
int ss = n + m + , tt = ;
G.init();
for(int i = ; i <= n; ++i) G.add_edge(ss, i, INF);
for(int i = ; i <= L; ++i) {
scanf("%d%d%d", &from[i], &to[i], &c);
G.add_edge(from[i], to[i], c);
}
//printf("%d\n", G.Max_flow(ss, tt, ss));
G.Max_flow(ss, tt, ss);
G.make_cut();
bool flag = false;
for(int i = ; i <= L; ++i) {
int &u = from[i], &v = to[i];
if(G.mark[u] == && G.mark[v] == ) {
if(flag) printf(" ");
printf("%d", i);
flag = true;
}
}
puts("");
}
}

ZOJ 2532 Internship(最大流找关键割边)的更多相关文章

  1. ZOJ 2532 Internship 求隔边

    Internship Time Limit: 5 Seconds      Memory Limit: 32768 KB CIA headquarter collects data from acro ...

  2. zoj 2532 Internship【最小割】

    就是求哪些边在最大流上满流,也就是找割边.把0作为t点,s向所有的1~n连流量为inf的边,其他的边按照流量连.跑一遍最大流,从s顺着有残余流量的正向边dfs打标记fr,从t顺着正向边有残余流量的反向 ...

  3. ZOJ 2532 Internship

    Internship Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: ...

  4. B - Internship (网络流关键割边)

    题目链接:https://cn.vjudge.net/contest/281961#problem/B 题目大意:给你n个城市,中间有一些中转站,然后给你终点,再给你l条轨道以及流量,问你增加哪几条轨 ...

  5. poj 3204(最小割--关键割边)

    Ikki's Story I - Road Reconstruction Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 7 ...

  6. POJ3204 Ikki's Story - Road Reconstruction 网络流图的关键割边

    题目大意:一个有源有汇的城市,问最少增加城市中的多少道路可以增加源到汇上各个路径上可容纳的总车流量增加. 网络流关键割边集合指如果该边的容量增加,整个网络流图中的任意从原点到汇点的路径的流量便可增加. ...

  7. hdu3313 最大流找关键点,或者最短路找关键点.

    题意:      给你一个有向图,然后给你起点和终点,问你从起点到终点有多少个关键点,如果当前的这个点删除了就无法从起点到终点,那么这个点就是一个关键点.. 思路:      (1)有两种做法,我用的 ...

  8. hdu 4975 A simple Gaussian elimination problem 最大流+找环

    原题链接 http://acm.hdu.edu.cn/showproblem.php?pid=4975 这是一道很裸的最大流,将每个点(i,j)看作是从Ri向Cj的一条容量为9的边,从源点除法连接每个 ...

  9. HDU-3416 Marriage Match IV 最短路+最大流 找各最短路的所有边

    题目链接:https://cn.vjudge.net/problem/HDU-3416 题意 给一个图,求AB间最短路的条数(每一条最短路没有重边.可有重复节点) 思路 首先把全部最短路的边找出来,再 ...

随机推荐

  1. DW CS5序列号

    先要改host文件,以防止其连接 Adobe 的激活验证服务器 1. 用记事本编辑“C:\Windows\System32\Drivers\etc\”目录下的 hosts 文件, 在末尾加上: 127 ...

  2. 解决jquey中当事件嵌套时,内层事件会执行多次的问题

    出现情景:当内层事件需要外层事件触发后产生的一些值得时候 情景复现: <!DOCTYPE html> <html lang="en"> <head&g ...

  3. js判断当前浏览器是否是源生app的webview

    有些时候,我们在开发过程中需要判断,当前页面被打开是否是处于源生的webview里面,或者NODEJS做服务器后端支持的时候,判断请求来源是否来至于源生webview里面被打开的页面请求GET/POS ...

  4. Sass使用

    1. 什么是Sass ???   Sass是一个将脚本解析成CSS的脚本语言,也可以称为CSS扩展语言. 2. 安装: 第一步:先安装Ruby (sass基于Ruby语言开发而成,因此安装sass前需 ...

  5. 【JVM】上帝视角看JVM内存模型,分而治之论各模块详情

    1. 上帝视角 [树看JVM] [图看JVM] 2. 分而治之 2.1 堆区 构成:堆区由新生代和老年代组成,新生代中包含伊甸区(Eden).幸存者区(survivor from .survivor ...

  6. Java : Spring基础 AOP

    简单的JDK动态代理例子(JDK动态代理是用了接口实现的方式)(ICar是接口, GoogleCar是被代理对象, MyCC是处理方法的类): public class TestCar { publi ...

  7. keil5最新版安装与破解

    1. 下载链接: https://pan.baidu.com/s/1BIrhqmxWdHY7hvihE0Wd4A 密码: cp45 2. 解压缩后得到: 3. 运行mdk526.exe安装keil5. ...

  8. HttpClient的Content-Type设置

    HttpClient的Content-Type设置 最近在对接公司内容的一个云服务的时候,遇到一个问题,就是如果使用HttpClient如何设置post时候的Content-Type? public ...

  9. 不使用IDE,用maven命令打包war项目及出现的问题解决(最全攻略,亲测有效)

    第一次在博客园写博客,写的不好大家见谅啊!! 一.首先,在用maven打包之前,一定确认好你使用的jdk版本和maven的版本,最好就是用jdk1.8和maven3.3以上的,版本太低了容易出现一些意 ...

  10. 利用cross-entropy cost代替quadratic cost来获得更好的收敛

    1.从方差代价函数说起(Quadratic cost) 代价函数经常用方差代价函数(即采用均方误差MSE),比如对于一个神经元(单输入单输出,sigmoid函数),定义其代价函数为: 其中y是我们期望 ...