Internship


Time Limit: 5 Seconds      Memory Limit: 32768 KB

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.

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> 有n个城市和m个中转站,有一个数据接收站(编号为0),城市从1---n编号,中转站从n+1---m编号,数据从每个城市发出最后到接收站接受,现在问提高哪些边中一条的容量使得接收站接收的数据增加 http://www.cnblogs.com/staginner/archive/2012/08/11/2633751.html
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=0x7fffffff;
const int MAXD=;
const int MAXM=;
int N,M,L,e,first[MAXD],next[MAXM],u[MAXM],v[MAXM],flow[MAXM];
int S,T,d[MAXD],q[MAXD],viss[MAXD],vist[MAXD];
int ch[],ans[MAXD],A;
void add(int x,int y,int z){
u[e]=x,v[e]=y,flow[e]=z;
next[e]=first[x],first[x]=e++;
}
void init(){
int x,y,z;
T=,S=N+M+;
memset(first,-,sizeof(first));
e=;
for(int i=;i<L;++i) {
scanf("%d%d%d",&x,&y,&z);
add(x,y,z),add(y,x,);
}
for(int i=;i<=N;++i) add(S,i,INF),add(i,S,);
}
bool bfs(){
int r=;
memset(d,-,sizeof(d));
d[S]=,q[r++]=S;
for(int i=;i<r;++i) for(int j=first[q[i]];j+;j=next[j]){
if(flow[j]&&d[v[j]]==-) {
d[v[j]]=d[q[i]]+,q[r++]=v[j];
if(v[j]==T) return true;
}
}
return false;
}
int dfs(int cur,int a){
if(cur==T||!a) return a;
for(int i=first[cur];~i;i=next[i])
if(flow[i]&&d[v[i]]==d[cur]+)
if(int t=dfs(v[i],std::min(a,flow[i]))) {
flow[i]-=t;flow[i^]+=t;
return t;
}
return ;
}
void dinic(){
while(bfs()) dfs(S,INF);
}
void DFS(int cur,int *vis,int k){
vis[cur]=;
for(int i=first[cur];i+;i=next[i]) if(!vis[v[i]]&&flow[i^k]) DFS(v[i],vis,k);
}
void solve(){
dinic();
memset(viss,,sizeof(viss));
memset(vist,,sizeof(vist));
DFS(S,viss,),DFS(T,vist,);
A=;
for(int i=;i<L;++i) if(flow[i<<]==&&viss[u[i<<]]&&vist[v[i<<]]) ans[A++]=i+;
if(A) {
printf("%d",ans[]);
for(int i=;i<A;++i) printf(" %d",ans[i]);
}
puts("");
}
int main(){
while(scanf("%d%d%d",&N,&M,&L),N){
init();
solve();
}
}

  

												

ZOJ2532判断边是否是割集中的边的更多相关文章

  1. JS判断网页是否在微信中打开/

    JS判断网页是否在微信中打开,代码如下: <script type="text/javascript"> function is_weixn(){ var ua = n ...

  2. stop() 是用于停止动画 :animated 用于判断动画是否在进行中

    stop() 是用于停止动画 if($("element").is(":animated"))  用于判断动画是否在进行中

  3. sql判断以逗号分隔的字符串中是否包含某个字符串--------MYSQL中利用select查询某字段中包含以逗号分隔的字符串的记录方法

    sql判断以逗号分隔的字符串中是否包含某个字符串---------------https://blog.csdn.net/wttykj/article/details/78520933 MYSQL中利 ...

  4. Js的iframe相关问题,如何判断当前是否在iframe中,iframe和它的父窗口如何通信

    一.前言: 在web中,为了丰富我们的内容,往往需要引用其它HTML文件,这时候就需要用到 iframe 标签,本文就主要记录一下使用iframe所需要注意的问题 iframe 所使用的环境(笔者所遇 ...

  5. 判断页面是否在iframe中,

    //判断页面是否在iframe中,是的话就跳出iframe框,多用于登录页  ,将此段代码放到要做判断的页面上即可 if (window != top) { top.location.href = l ...

  6. 分享一段js,判断是否是在iPhone中的Safari浏览器打开的页面

    头部引用jquery包 将下面的一段js写在</body>的前面 <script type="text/javascript"> var ua = navi ...

  7. 从a文件判断是否删除b文件中的行(sed示例)

    bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html test.xml文件很大,内容结构如下: <?xml v ...

  8. js 判断元素是否在列表中

    /** * 使用循环的方式判断一个元素是否存在于一个数组中 * @param {Object} arr 数组 * @param {Object} value 元素值 */ function isInA ...

  9. Codeforces Round #306 (Div. 2) A. Two Substrings【字符串/判断所给的字符串中是否包含不重叠的“BA” “AB”两个字符串】

    A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

随机推荐

  1. vue与众不同的学习方式,让她年薪200多万

    学习vue正确思路,是先学vue-cli,再学vue.js单文件引用的用法,这样会在极短时间内撤底撑握vue,如果先学vue.js单文件用法,再去学vue-cli4,可以说是重新学vue,,,,难处大 ...

  2. 【蜕变之路】第20天 UUID和时间戳的生成 (2019年3月10日)

    Hello,大家好!我是程序员阿飞!今天主要学习的内容是:字符串UUID的随机生成和时间戳的随机生成.好了,直接进入正题. 1.UUID的随机生成 /*          * uuid的随机生成方式 ...

  3. Babel 在浏览器环境使用方法

    Babel 也可以用于浏览器环境.但是,从 Babel 6.0 开始,不再直接提供浏览器版本,而是要用构建工具构建出来.如果你没有或不想使用构建工具 1.通过安装5.x版本的babel-core模块获 ...

  4. 如何在github上递交高质量的pull request

    开源的一大乐趣就是任何人都可以参与其中.试想下一个流行的项目就有你贡献的代码,是一件多么爽的事情!你可以帮助项目健康发展,添加你希望添加的功能,以及修复你发现的BUG. 作为全球最大的开源社区GitH ...

  5. How to get binary string from ArrayBuffer?

    https://stackoverflow.com/questions/16363419/how-to-get-binary-string-from-arraybuffer https://stack ...

  6. golang 容器的学习与实践

    golang 提供了几个简单的容器供我们使用,本文在介绍几种Golang 容器的基础上,实现一个基于Golang 容器的LRU算法. 容器介绍 Golang 容器位于 container 包下,提供了 ...

  7. hadoop中如何动态更新集群队列和容量

    1.集群默认是FIFO容量调度器,有的时候不同的业务部门都需要使用hadoop集群,那么这时候就需要来设置容量调度器了,如何平衡各个部门的容量.合理利用资源? 首先配置调度器需要在修改两个配置文件,分 ...

  8. 吴恩达机器学习week2

    1.Mean normalization(均值归一化) 我们可以将均值归一化理解为特征缩放的另一种方法. 特征缩放和均值归一化的作用都是为了减小样本数据的波动使得梯度下降能够更快速的寻找到一条'捷径' ...

  9. javaScript 添加和移除class类名的几种方法

    添加类属性: // 一次只能设置一个类值,如果当前属性本身存在类值,会被替换 element.className = '类名'; /* * .setAttribute 用来设置自定义属性和值的 * 自 ...

  10. Vue + Element-ui实现后台管理系统(3)---面包屑 + Tag标签切换功能

    面包屑 + Tag标签切换功能 有关后台管理系统之前写过两遍博客,看这篇之前最好先看下这两篇博客.另外这里只展示关键部分代码,项目代码放在github上: mall-manage-system 1.V ...