ZOJ 2532 Internship 求隔边

Posted qldabiaoge

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZOJ 2532 Internship 求隔边相关的知识,希望对你有一定的参考价值。

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

 

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <queue>
  4 #include <cmath>
  5 #include <algorithm>
  6 #include <set>
  7 #include <iostream>
  8 #include <map>
  9 #include <stack>
 10 #include <string>
 11 #define pi acos(-1.0)
 12 #define eps 1e-6
 13 #define fi first
 14 #define se second
 15 #define lson l,m,rt<<1
 16 #define rson m+1,r,rt<<1|1
 17 #define bug      printf("******")
 18 #define mem(a,b) memset(a,b,sizeof(a))
 19 #define fuck(x)  cout<<"["<<x<<"]"<<endl
 20 #define f(a)     a*a
 21 #define san(n,m) scanf("%d%d",&n,&m)
 22 #define FIN freopen("in.txt","r",stdin)
 23 #define lowbit(x) x&-x
 24 #pragma comment (linker,"/STACK:102400000,102400000")
 25 using namespace std;
 26 const int maxn = 10004;
 27 typedef long long LL;
 28 const int MX = 10050;
 29 const int MXE = 4 * MX * MX;
 30 const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
 31 const int INF = 0x3f3f3f;
 32 struct Edge {
 33     int v, u, nxt;
 34     LL w;
 35 } edge[maxn];
 36 int tot, num, s, t;
 37 int head[MX];
 38 void init() {
 39     memset (head, -1, sizeof (head) );
 40     tot = 0;
 41 }
 42 void add (int u, int v, LL w) {
 43     edge[tot].v = v;
 44     edge[tot].u = u;
 45     edge[tot].w = w;
 46     edge[tot].nxt = head[u];
 47     head[u] = tot++;
 48 }
 49 int  d[MX], vis[MX], gap[MX];
 50 void bfs() {
 51     memset (d, 0, sizeof (d) );
 52     memset (gap, 0, sizeof (gap) );
 53     memset (vis, 0, sizeof (vis) );
 54     queue<int>q;
 55     q.push (t);
 56     vis[t] = 1;
 57     while (!q.empty() ) {
 58         int u = q.front();
 59         q.pop();
 60         for (int i = head[u]; ~i; i = edge[i].nxt) {
 61             int v = edge[i].v;
 62             if (!vis[v]) {
 63                 d[v] = d[u] + 1;
 64                 gap[d[v]]++;
 65                 q.push (v);
 66                 vis[v] = 1;
 67             }
 68         }
 69     }
 70 }
 71 int last[MX];
 72 LL dfs (int u, LL f) {
 73     if (u == t) return f;
 74     LL sap = 0;
 75     for (int i = last[u]; ~i; i = edge[i].nxt) {
 76         int v = edge[i].v;
 77         if (edge[i].w > 0 && d[u] == d[v] + 1) {
 78             last[u] = i;
 79             LL tmp = dfs (v, min (f - sap, edge[i].w) );
 80             edge[i].w -= tmp;
 81             edge[i ^ 1].w += tmp;
 82             sap += tmp;
 83             if (sap == f) return sap;
 84         }
 85     }
 86     if (d[s] >= num) return sap;
 87     if (! (--gap[d[u]]) ) d[s] = num;
 88     ++gap[++d[u]];
 89     last[u] = head[u];
 90     return sap;
 91 }
 92 LL solve (int st, int ed, int n) {
 93     LL flow = 0;
 94     num = n;
 95     s = st;
 96     t = ed;
 97     bfs();
 98     memcpy (last, head, sizeof (head) );
 99     while (d[s] < num) flow += dfs (s, INFLL);
100     return flow;
101 }
102 int vis1[maxn], vis2[maxn], n, m, l, ans[maxn];
103 void dfs1(int u, int *vist, int op) {
104     vist[u] = true;
105     for(int i = head[u]; i != -1; i = edge[i].nxt) {
106         if(!vist[edge[i].v] && edge[i ^ op].w != 0) {
107             dfs1(edge[i].v, vist, op);
108         }
109     }
110 }
111 
112 int main() {
113     int l;
114     while(~scanf("%d%d%d", &n, &m, &l)) {
115         init();
116         if(n + m + l == 0) break;
117         s = n + m + 1;
118         t = 0;
119         int a, b, c;
120         for(int i = 0; i < l; i++) {
121             scanf("%d %d %d", &a, &b, &c);
122             add(a, b, c);
123             add(b, a, 0);
124         }
125         for(int i = 1; i <= n; i++) {
126             add(s, i, INF);
127             add(i, s, 0);
128         }
129         solve ( s,  t, n + m + 2) ;
130         memset(vis1, false, sizeof(vis1));
131         memset(vis2, false, sizeof(vis2));
132         dfs1(s, vis1, 0);
133         dfs1(t, vis2, 1);
134         int num = 0;
135         for(int i = 0; i < l; i++) {
136             if(edge[i << 1].w == 0 && vis1[edge[i << 1].u] && vis2[edge[i << 1].v]) {
137                 ans[num++] = i + 1; 
138             }
139         }
140         if(num) {
141             for(int i = 0; i < num; i++) {
142                 if(i)  printf(" ");
143                 printf("%d", ans[i]);
144             }
145         }
146         printf("
");
147     }
148     return 0;
149 }

 

 







以上是关于ZOJ 2532 Internship 求隔边的主要内容,如果未能解决你的问题,请参考以下文章

ZOJ 1532 Internship (Dinic)

ZOJ2532判断边是否是割集中的边

CA秋招丨Microsoft开放销售类科技类2021 Internship!

2020春招 | Microsoft Finance Analyst Summer Internship

The twelfth day of internship

春招丨BNP 已开放哥大/NYU Spring Internship Opportunities Fair!