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

Posted Billyshuai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
    }
}

 

  



以上是关于ZOJ2532判断边是否是割集中的边的主要内容,如果未能解决你的问题,请参考以下文章

ZOJ2540 Form a Square

ZOJ 2532 Internship 求隔边

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

ZOJ 3496 Assignment | 二分+有上下界网络流

图论中的点割集,割点是啥意思啊,看书上的定义看不懂,能不能通俗的讲解一下

ZOJ2588 Burning Bridges(割边)