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

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=110;
const int MAXM=2210;
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[5],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=0,S=N+M+1;
   memset(first,-1,sizeof(first));
   e=0;
   for(int i=0;i<L;++i) {
    scanf("%d%d%d",&x,&y,&z);
    add(x,y,z),add(y,x,0);
   }
   for(int i=1;i<=N;++i)  add(S,i,INF),add(i,S,0);
}
bool bfs(){
   int r=0;
   memset(d,-1,sizeof(d));
   d[S]=0,q[r++]=S;
   for(int i=0;i<r;++i) for(int j=first[q[i]];j+1;j=next[j]){
    if(flow[j]&&d[v[j]]==-1) {
        d[v[j]]=d[q[i]]+1,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]+1)
   if(int t=dfs(v[i],std::min(a,flow[i]))) {
    flow[i]-=t;flow[i^1]+=t;
    return t;
   }
   return 0;
}
void dinic(){
    while(bfs()) dfs(S,INF);
}
void DFS(int cur,int *vis,int k){
    vis[cur]=1;
    for(int i=first[cur];i+1;i=next[i]) if(!vis[v[i]]&&flow[i^k]) DFS(v[i],vis,k);
}
void solve(){
    dinic();
    memset(viss,0,sizeof(viss));
    memset(vist,0,sizeof(vist));
    DFS(S,viss,0),DFS(T,vist,1);
    A=0;
    for(int i=0;i<L;++i) if(flow[i<<1]==0&&viss[u[i<<1]]&&vist[v[i<<1]]) ans[A++]=i+1;
    if(A) {
        printf("%d",ans[0]);
        for(int i=1;i<A;++i) printf(" %d",ans[i]);
    }
    puts("");
}
int main(){
    while(scanf("%d%d%d",&N,&M,&L),N){
        init();
        solve();
    }
}

  

				
时间: 2024-10-10 09:42:02

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

判断JSON返回的对象中的firstName这一列的值是否包含指定的字符

判断JSON返回的对象中的firstName这一列的值是否包含指定的字符,如果包含指定字符则返回true,否则返回false 标签: <无> 代码片段(1)[全屏查看所有代码] 1. [代码][其他]代码 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

JavaScript 的in 操作符 (“如何判断某值是否数组中的元素”?)

在编写JavaScript时,遇到一个常见的问题"如何判断某值是否数组中的元素"?这让我想起了PHP中的in_array()函数和Python中in 操作符.但JavaScript似乎没有内置类似的函数,而其in 操作符的作用也有点不同.通过查询相关的资料,我发现JavaScript的in 操作符还是挺有用的. 一.问题让我想到in 操作符,正是因为这样一个问题:"如何判断某值是否数组中的元素"?在PHP中,您可能会这样来处理: $os = array("

【华为练习题】判断点是否在三角形中

[华为练习题]判断点是否在三角形中 题目 一个二维坐标系中(100*100,每一维0~99),已知三角形三个顶点的坐标A.B.C,判断坐标系中的任意点:P,是否在三角形内(在三角形边上也认为在三角形内) 请实现如下接口 /* 功能:点是否在三角形内 输入:三角形三顶点坐标:A.B.C,以及待确认的点:P 输出:无 返回:在三角形内返回true,否则返回false */ public static boolean isInTriangle(POINTA, POINTB, POINTC, POINT

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

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

[JavaScript] js判断是否在微信浏览器中打开

用JS来判断了,经过查找资料终于实现了效果, function is_weixn(){     var ua = navigator.userAgent.toLowerCase();     if(ua.match(/MicroMessenger/i)=="micromessenger") {         return true;     } else {         return false;     } } 通过测试完全通过,无论是android 还是iphone,ipad

坐标画图形,发射线判断点是否在图形中

创建一个点的bean public class Point { private double lat; private double lon; public double getLat() { return lat; } public void setLat(double lat) { this.lat = lat; } public double getLon() { return lon; } public void setLon(double lon) { this.lon = lon;

判断页面是否在iframe中,

//判断页面是否在iframe中,是的话就跳出iframe框,多用于登录页  ,将此段代码放到要做判断的页面上即可 if (window != top) { top.location.href = location.href; } 原文地址:https://www.cnblogs.com/qqing/p/8143689.html

javascript判断元素是否在数组中

代码: /* @desc:判断元素是否在数组中 @param value 需要判断的元素 @param arr 要检测的数组 @return true:在数组中 flase:不在数组中 */ function inarray(value,arr){ for(var i = 0; i < arr.length; i++){ if(value === arr[i]){ return true; } } return false; } 测试: var arr = [1,2,5] var value =

读取一个文件,给定一个字符串,判断这个字符串在文件中出现的次数

读取一个文件,给定一个字符串,判断这个字符串在文件中出现的次数,面试笔试经常遇到的问题 public class CountStringTest { public static void main(String[] args) { try { //统计E盘下面test.txt中的q字符出现的次数 System.out.println("E盘下面test.txt中的q字符出现的次数为:"); System.err.println(count("E:\\test.txt"