Internship


Time Limit: 5 Seconds      Memory Limit: 32768 KB

CIA headquarter collects data from across the country through its classified network. They have been usingoptical fibres long before it's been deployed on any civilian projects. However they are still under a lotpressure recently because the data are growing rapidly. As a result they are considering upgrading thenetwork 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. Andas a CIA intern it's your responsibility to investigate which segment could actually help increasethe total bandwidth the headquarter receives, suppose that all the cities have infinite data to sendand the routing algorithm is optimized. As they have prepared the data for you in a few minutes, you aretold 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, theyrepresent the number of cities, the number of relay stations and the number of segments. Cities will bereferred to as integers from 1 to n, while relay stations use integers from n+1 to n+m. You can savesassume that n + m <= 100, l <= 1000 (all of them are positive). The headquarter is identified by theinteger 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 isthe 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 canbe 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 lineand sorted in ascending order, with a single space as the separator. If none of the segment meets thecriteria, just print an empty line. The segment id is 1 based not 0 based.

Sample Input

2 1 3
1 3 2
3 0 1
2 0 1
2 1 3
1 3 1
2 3 1
3 0 2
0 0 0

Sample Output

2 3
<hey here is an invisible empty line>
Author: WU, Jiazhi

题意

CIA公司想采用新技术升级网络,在实验测试阶段,他们想升级其中的一段网络以便观察新技术在多大的长度上提升网络的性能,你作为实习生的任务是调查那一段网络能提高CIA总部的宽带。

思路

找割边集。 
判断一段网络可不可以提升网络就要看它是不是满流,如果满流则可能在升级后提升CIA总部的宽带,但是如果提升后并不能增广,即不能提升CIA总部的宽带,所以判断一段是不是可提升的则有两个条件:(1)在进行增广后这段网络是满流的,(2)在提升后可以增广。

所以从源DFS一次,标记,从汇DFS一次,标记。再枚举边,判断。

以上内容来自  https://blog.csdn.net/xzxxzx401/article/details/78313184

 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define san(n,m) scanf("%d%d",&n,&m)
#define FIN freopen("in.txt","r",stdin)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
const int maxn = ;
typedef long long LL;
const int MX = ;
const int MXE = * MX * MX;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int INF = 0x3f3f3f;
struct Edge {
int v, u, nxt;
LL w;
} edge[maxn];
int tot, num, s, t;
int head[MX];
void init() {
memset (head, -, sizeof (head) );
tot = ;
}
void add (int u, int v, LL w) {
edge[tot].v = v;
edge[tot].u = u;
edge[tot].w = w;
edge[tot].nxt = head[u];
head[u] = tot++;
}
int d[MX], vis[MX], gap[MX];
void bfs() {
memset (d, , sizeof (d) );
memset (gap, , sizeof (gap) );
memset (vis, , sizeof (vis) );
queue<int>q;
q.push (t);
vis[t] = ;
while (!q.empty() ) {
int u = q.front();
q.pop();
for (int i = head[u]; ~i; i = edge[i].nxt) {
int v = edge[i].v;
if (!vis[v]) {
d[v] = d[u] + ;
gap[d[v]]++;
q.push (v);
vis[v] = ;
}
}
}
}
int last[MX];
LL dfs (int u, LL f) {
if (u == t) return f;
LL sap = ;
for (int i = last[u]; ~i; i = edge[i].nxt) {
int v = edge[i].v;
if (edge[i].w > && d[u] == d[v] + ) {
last[u] = i;
LL tmp = dfs (v, min (f - sap, edge[i].w) );
edge[i].w -= tmp;
edge[i ^ ].w += tmp;
sap += tmp;
if (sap == f) return sap;
}
}
if (d[s] >= num) return sap;
if (! (--gap[d[u]]) ) d[s] = num;
++gap[++d[u]];
last[u] = head[u];
return sap;
}
LL solve (int st, int ed, int n) {
LL flow = ;
num = n;
s = st;
t = ed;
bfs();
memcpy (last, head, sizeof (head) );
while (d[s] < num) flow += dfs (s, INFLL);
return flow;
}
int vis1[maxn], vis2[maxn], n, m, l, ans[maxn];
void dfs1(int u, int *vist, int op) {
vist[u] = true;
for(int i = head[u]; i != -; i = edge[i].nxt) {
if(!vist[edge[i].v] && edge[i ^ op].w != ) {
dfs1(edge[i].v, vist, op);
}
}
} int main() {
int l;
while(~scanf("%d%d%d", &n, &m, &l)) {
init();
if(n + m + l == ) break;
s = n + m + ;
t = ;
int a, b, c;
for(int i = ; i < l; i++) {
scanf("%d %d %d", &a, &b, &c);
add(a, b, c);
add(b, a, );
}
for(int i = ; i <= n; i++) {
add(s, i, INF);
add(i, s, );
}
solve ( s, t, n + m + ) ;
memset(vis1, false, sizeof(vis1));
memset(vis2, false, sizeof(vis2));
dfs1(s, vis1, );
dfs1(t, vis2, );
int num = ;
for(int i = ; i < l; i++) {
if(edge[i << ].w == && vis1[edge[i << ].u] && vis2[edge[i << ].v]) {
ans[num++] = i + ;
}
}
if(num) {
for(int i = ; i < num; i++) {
if(i) printf(" ");
printf("%d", ans[i]);
}
}
printf("\n");
}
return ;
}
												

ZOJ 2532 Internship 求隔边的更多相关文章

  1. ZOJ 2532 Internship

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

  2. ZOJ 2532 Internship(最大流找关键割边)

    Description CIA headquarter collects data from across the country through its classified network. Th ...

  3. zoj 2532 Internship【最小割】

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

  4. ZOJ 3822(求期望)

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  5. Saddle Point ZOJ - 3955(求每个值得贡献)

    题意: 给出一个矩阵,删掉一些行和列之后 求剩下矩阵的鞍点的总个数 解析: 对于每个点 我们可以求出来 它所在的行和列  有多少比它大的 设为a 有多少比它小的 设为b 然后对于那些行和列 都有两种操 ...

  6. ZOJ 3537 Cake 求凸包 区间DP

    题意:给出一些点表示多边形顶点的位置(如果多边形是凹多边形就不能切),切多边形时每次只能在顶点和顶点间切,每切一次都有相应的代价.现在已经给出计算代价的公式,问把多边形切成最多个不相交三角形的最小代价 ...

  7. ZOJ 2532 网络流最小割

    求最小割的问题. 题意:已知网络中有n个源点,m的中转站(也就是节点),一个汇点(编号为0).给出网络,求一些边(增大这个边就可以增大汇点流量的边). 思路:一开始代码只找了有流=0就加入输出数组的情 ...

  8. ZOJ 3795 Grouping 求最长链序列露点拓扑

    意甲冠军:特定n积分.m向边条. 该点被划分成多个集合随机的每个集合,使得2问题的关键是无法访问(集合只能容纳一个点) 问至少需要被分成几个集合. 假设没有戒指,接着这个话题正在寻求产业链最长的一个有 ...

  9. ZOJ 1532 Internship (Dinic)

    看来模板又错了,敲你妈妈小饼干 #include<iostream> #include<queue> #include<cstring> #include<c ...

随机推荐

  1. Oracle启动与关闭数据库实例

    Oracle数据库启动实例分为3个步骤: 启动实例 加载数据库 打开数据库 通用模式: STARTUP  [ nomount | mount | open | force ]  [resetrict] ...

  2. python数据文件读写

    CSV格式读写 Comma-Separated Values 有时也称为字符分隔值,因为分隔字符也可以不是逗号.以,分隔的文件叫csv,以\t分隔的叫tsv 需要注意的一点:分隔符 import cs ...

  3. Js全反选DataGrid

    // **************************************************************** // // function Trim(value) // -- ...

  4. Python3 Tkinter-Menu

    1.创建 from tkinter import * root=Tk() menubar=Menu(root) def hello(): print('Hello Menu!') for item i ...

  5. mysql数据库配置主从同步

    MySQL主从同步的作用 .可以作为一种备份机制,相当于热备份 .可以用来做读写分离,均衡数据库负载 MySQL主从同步的步骤 一.准备操作 .主从数据库版本一致,建议版本5.5以上 .主从数据库数据 ...

  6. forward_list

    一.特性 单向链表,只支持单向顺序访问(不支持快速随机访问),是C++11标准新增的类型 可类比于数据结构——单(向)链表 1. 没有size操作 forward_list为了追求性能,省去了size ...

  7. 一步步学敏捷开发:1、敏捷开发及Scrum介绍

    敏捷开发之 历史背景 20世纪60年代:软件作坊,软件规模小,以作坊式开发为主:70年代:软件危机,硬件飞速发展,软件规模和复杂度激增,引发软件危机:80年代:软件过程控制,引入成熟生产制造管理方法, ...

  8. GPS定位,经纬度附近地点查询–C#实现方法

              摘要:目前的工作是需要手机查找附近N米以内的商户,功能如下图数据库中记录了商家在百度标注的经纬度(如:116.412007,39.947545),最初想法以圆心点为中心点,对半径做 ...

  9. Qt自定义标题栏

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt自定义标题栏     本文地址:http://techieliang.com/2017/1 ...

  10. node中的__dirname

    先说结论:__dirname指的是当前文件所在文件夹的绝对路径. 测试路径如下: 即 根目录/dir0.js 根目录/path1/dir1.js 根目录/paht1/path2/dir2.js 每个d ...