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

  1. 2 1 3
  2. 1 3 2
  3. 3 0 1
  4. 2 0 1
  5. 2 1 3
  6. 1 3 1
  7. 2 3 1
  8. 3 0 2
  9. 0 0 0

Sample Output

  1. 2 3
  2. <hey here is an invisible empty line>

Author: WU, Jiazhi

Source: CYJJ's Funny Contest #3, Having Fun in Summer

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

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

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <map>
  8. #include <set>
  9. #include <vector>
  10. #include <algorithm>
  11.  
  12. using namespace std;
  13.  
  14. const int INF = 0x3f3f3f3f;
  15.  
  16. typedef struct node
  17. {
  18.  
  19. int u;
  20.  
  21. int v;
  22.  
  23. int Flow;
  24.  
  25. int next;
  26. }Line;
  27.  
  28. Line Li[2200];
  29.  
  30. int Head[110],top;
  31.  
  32. int vis[110],ans[110];
  33.  
  34. bool vis1[110],vis2[110];
  35.  
  36. int n,m,l;
  37.  
  38. int s,t;
  39.  
  40. void AddEdge(int u,int v,int f)
  41. {
  42. Li[top].v=v; Li[top].u=u;
  43. Li[top].Flow=f;
  44. Li[top].next=Head[u];
  45. Head[u]=top++;
  46. }
  47.  
  48. bool BFS()
  49. {
  50. memset(vis,-1,sizeof(vis));
  51.  
  52. vis[s]=0;
  53.  
  54. queue<int >Q;
  55.  
  56. Q.push(s);
  57.  
  58. while(!Q.empty())
  59. {
  60.  
  61. int u=Q.front();
  62.  
  63. Q.pop();
  64.  
  65. for(int i=Head[u];i!=-1;i=Li[i].next)
  66. {
  67.  
  68. if(Li[i].Flow&&vis[Li[i].v]==-1)
  69. {
  70. vis[Li[i].v]=vis[u]+1;
  71.  
  72. Q.push(Li[i].v);
  73.  
  74. }
  75. }
  76. }
  77. return vis[t]!=-1;
  78.  
  79. }
  80.  
  81. int DFS(int u,int f)
  82. {
  83. if(u==t)
  84. {
  85. return f;
  86. }
  87. int ans=0;
  88.  
  89. for(int i=Head[u];i!=-1;i=Li[i].next)
  90. {
  91. if(Li[i].Flow&&vis[Li[i].v]==vis[u]+1)
  92. {
  93. int d=DFS(Li[i].v,min(f,Li[i].Flow));
  94. f-=d;
  95. Li[i].Flow-=d;
  96. Li[i^1].Flow+=d;
  97. ans+=d;
  98. }
  99. }
  100. return ans;
  101. }
  102.  
  103. void dfs(int u,bool *vist,int op)
  104. {
  105. vist[u]=true;
  106.  
  107. for(int i=Head[u];i!=-1;i=Li[i].next)
  108. {
  109. if(!vist[Li[i].v]&&Li[i^op].Flow!=0)
  110. {
  111. dfs(Li[i].v,vist,op);
  112. }
  113. }
  114. }
  115.  
  116. void Dinic()//网络流进行增广
  117. {
  118. int ans;
  119.  
  120. while(BFS())
  121. {
  122. ans=DFS(s,INF);
  123.  
  124. }
  125. }
  126.  
  127. int main()
  128. {
  129. while(~scanf("%d %d %d",&n,&m,&l))
  130. {
  131.  
  132. if(n+m+l==0)
  133. {
  134. break;
  135. }
  136.  
  137. s=n+m+1;//源点
  138.  
  139. t=0;//汇点
  140.  
  141. memset(Head,-1,sizeof(Head));
  142.  
  143. int a,b,c;
  144.  
  145. top = 0;
  146.  
  147. for(int i=0;i<l;i++)
  148. {
  149. scanf("%d %d %d",&a,&b,&c);
  150. AddEdge(a,b,c);//建立边,正向为c,负向为0
  151. AddEdge(b,a,0);
  152. }
  153.  
  154. for(int i=1;i<=n;i++)
  155. {
  156. AddEdge(s,i,INF);
  157.  
  158. AddEdge(i,s,0);//建立城市与源点之间的边,权值为INF
  159. }
  160.  
  161. Dinic();
  162.  
  163. memset(vis1,false,sizeof(vis1));
  164.  
  165. memset(vis2,false,sizeof(vis2));
  166.  
  167. dfs(s,vis1,0);//从源点向汇点搜索,标记还有剩余流的点
  168.  
  169. dfs(t,vis2,1);//从汇点到源点搜索,标记还有剩余流的点
  170.  
  171. int num=0;
  172.  
  173. for(int i=0;i<l;i++)
  174. {
  175. if(Li[i<<1].Flow==0&&vis1[Li[i<<1].u]&&vis2[Li[i<<1].v])
  176. {
  177. ans[num++]=i+1;//如果一条边的u与v都被标记,表明s->u,v->t,但是这条边是满流,所以提升这条边。
  178. }
  179. }
  180.  
  181. if(num)
  182. {
  183. for(int i=0;i<num;i++)
  184. {
  185. if(i)
  186. {
  187. printf(" ");
  188. }
  189. printf("%d",ans[i]);
  190. }
  191. }
  192. printf("\n");
  193.  
  194. }
  195. return 0;
  196. }

Internship-ZOJ2532(网络流求割边)的更多相关文章

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

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

  2. [学习笔记]tarjan求割边

    上午打模拟赛的时候想出了第三题题解,可是我不会求割边只能暴力判割边了QAQ 所以,本文介绍求割边(又称桥). 的定义同求有向图强连通分量. 枚举当前点的所有邻接点: 1.如果某个邻接点未被访问过,则访 ...

  3. 【NOIP训练】【Tarjan求割边】上学

    题目描述 给你一张图,询问当删去某一条边时,起点到终点最短路是否改变. 输入格式 第一行输入两个正整数,分别表示点数和边数.第二行输入两个正整数,起点标号为,终点标号为.接下来行,每行三个整数,表示有 ...

  4. ZOJ 2588 Burning Bridges (tarjan求割边)

    题目链接 题意 : N个点M条边,允许有重边,让你求出割边的数目以及每条割边的编号(编号是输入顺序从1到M). 思路 :tarjan求割边,对于除重边以为中生成树的边(u,v),若满足dfn[u] & ...

  5. ZOJ Problem - 2588 Burning Bridges tarjan算法求割边

    题意:求无向图的割边. 思路:tarjan算法求割边,访问到一个点,如果这个点的low值比它的dfn值大,它就是割边,直接ans++(之所以可以直接ans++,是因为他与割点不同,每条边只访问了一遍) ...

  6. HDU 4738——Caocao's Bridges——————【求割边/桥的最小权值】

     Caocao's Bridges Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. POJ3694(求割边)

    Network Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7943   Accepted: 2893 Descripti ...

  8. tarjan求割边割点

    tarjan求割边割点 内容及代码来自http://m.blog.csdn.net/article/details?id=51984469 割边:在连通图中,删除了连通图的某条边后,图不再连通.这样的 ...

  9. ZOJ 2588 求割边问题

    题目链接:http://vjudge.net/problem/viewProblem.action?id=14877 题目大意: 要尽可能多的烧毁桥,另外还要保证图的连通性,问哪些桥是绝对不能烧毁的 ...

随机推荐

  1. JDK+MyEclipse+Tomcat的配置(修改Tomcat 6.x的端口)

    修改tomcat的端口,在conf目录里的server.xml文件 例如想将端口修改为8080则将port的值修改为8081,其余值不变 通过Tomcat服务器访问 想通过浏览器访问这个页面,需要在T ...

  2. EmguCV 简单图形绘制

    一.圆 public static void cvCircle( IntPtr img, System.Drawing.Point center, //Center of the circle int ...

  3. 【iCore3 双核心板】例程三十:U_DISK_IAP_FPGA实验——更新升级FPGA

    实验指导书及代码包下载: http://pan.baidu.com/s/1jH1TiKY iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  4. 【7集iCore3基础视频】7-2 iCore3原理图介绍

    iCore3原理图介绍: 高清源视频:http://pan.baidu.com/s/1hsPkifM 密码:ei8ciCore3 购买链接:https://item.taobao.com/item.h ...

  5. NGUI 之 不为人知的 NGUITools

    static public float soundVolume该属性是全局音效播放音量,按照文档说是用于NGUITools.PlaySound(),那也就意味着我的游戏如果用NGUITools.Pla ...

  6. 有return语句情况下,try-catch-finally的执行顺序

    重要结论: 1.不管有没有出现异常,finally块中代码都会执行 2.当try和catch中有return时,finally仍然会执行 3.finally是在return后面的表达式运算后执行的(此 ...

  7. Tomcat负载均衡配置-未完成

    集群技术是目前非常流行的提高系统服务能力与高可靠性( HA- High Availability )的手段,通过把多个独立的服务器组成一个集群可以实现失效无缝转移.也就是说当有某一台集群中的服务器当机 ...

  8. http://highscalability.com/blog/2015/5/18/how-mysql-is-able-to-scale-to-200-million-qps-mysql-cluster.html

    http://highscalability.com/blog/2015/5/18/how-mysql-is-able-to-scale-to-200-million-qps-mysql-cluste ...

  9. Flink - RocksDBStateBackend

    如果要考虑易用性和效率,使用rocksDB来替代普通内存的kv是有必要的 有了rocksdb,可以range查询,可以支持columnfamily,可以各种压缩 但是rocksdb本身是一个库,是跑在 ...

  10. Java中Native关键字的作用

    初次遇见 native是在 java.lang.Object 源码中的一个hashCode方法: 1 public native int hashCode(); 为什么有个native呢?这是我所要学 ...