【ZOJ - 2587】 Unique Attack 【最小割是否唯一】

6人阅读 评论(0) 收藏 举报
分类:

N supercomputers in the United States of Antarctica are connected into a network. A network has a simple topology: M different pairs of supercomputers are connected to each other by an optical fibre. All connections are two-way, that is, they can be used in both directions. Data can be transmitted from one computer to another either directly by a fibre, or using some intermediate computers.

A group of terrorists is planning to attack the network. Their goal is to separate two main computers of the network, so that there is no way to transmit data from one of them to another. For each fibre the terrorists have calculated the sum of money they need to destroy the fibre. Of course, they want to minimize the cost of the operation, so it is required that the total sum spent for destroying the fibres was minimal possible.

Now the leaders of the group wonder whether there is only one way to do the selected operation. That is, they want to know if there are no two different sets of fibre connections that can be destroyed, such that the main supercomputers cannot connect to each other after it and the cost of the operation is minimal possible.

Input
The input file consists of several cases. In each case, the first line of the input file contains N, M, A and B (2 <= N <= 800, 1 <= M <= 10000, 1 <= A,B <= N, A != B), specifying the number of supercomputers in the network, the number of fibre connections, and the numbers of the main supercomputers respectively. A case with 4 zeros indicates the end of file.

Next M lines describe fibre connections. For each connection the numbers of the computers it connects are given and the cost of destroying this connection. It is guaranteed that all costs are non-negative integer numbers not exceeding 105, no two computers are directly connected by more than one fibre, no fibre connects a computer to itself and initially there is the way to transmit data from one main supercomputer to another.

Output
If there is only one way to perform the operation, output “UNIQUE” in a single line. In the other case output “AMBIGUOUS”.

Sample Input
4 4 1 2
1 2 1
2 4 2
1 3 2
3 4 1
4 4 1 2
1 2 1
2 4 1
1 3 2
3 4 1
0 0 0 0

Sample Output
UNIQUE
AMBIGUOUS

分析: 注意一点: 如果是割边的话那么其一定是满流,但是如果是满流不代表其一定为割边。
在残留网络中,如果有一个点是从s无法到达,t也无法到达。那说明这个点两端的边都是满流,同时 流进的流肯定等于 流出的流。 所以你割左端所有的边和割右端所有的边效果一定是一样的。

代码

#include<bits/stdc++.h>
using namespace std;
#define LL long long

const int N = 1000+11;
const int M = 1e5+11;
const int inf = 0x3f3f3f3f;

struct Edge {
    int form,to,cap,flow,nexts;
}edge[M];
int head[N],top;
void init(){
    memset(head,-1,sizeof(head));
    top=0;
}
void addedge(int a,int b,int c){
    Edge e={a,b,c,0,head[a]};
    edge[top]=e;head[a]=top++;

    Edge ee={b,a,0,0,head[b]};
    edge[top]=ee;head[b]=top++;
}
int vis[N],dis[N];
int cur[N];
bool bfs(int st,int ed){
    queue<int>Q;
    memset(vis,0,sizeof(vis));
    memset(dis,-1,sizeof(dis));
    Q.push(st);vis[st]=1;dis[st]=1;
    while(!Q.empty()){
        int now=Q.front();Q.pop();
        for(int i=head[now];i!=-1;i=edge[i].nexts){
            Edge e=edge[i];
            if(!vis[e.to]&&e.cap-e.flow>0){
                vis[e.to]=1;
                dis[e.to]=dis[now]+1;
                if(e.to==ed) return 1;
                Q.push(e.to);
            }
        }
    }
    return 0;
}
int dfs(int now,int a,int ed){
    if(a==0||now==ed) return a;
    int flow=0,f;
    for(int &i=cur[now];i!=-1;i=edge[i].nexts){
        Edge &e=edge[i];
        if(dis[e.to]==dis[now]+1&&(f=dfs(e.to,min(e.cap-e.flow,a),ed))>0){
            e.flow+=f;
            flow+=f;
            edge[i^1].flow-=f;
            a-=f;
            if(a==0) break;
        }
    }
    return flow;
}

int max_flow(int st ,int ed){
    int flow=0;
    while(bfs(st,ed)){
        memcpy(cur,head,sizeof(head));
        flow+=dfs(st,inf,ed);
    }
    return flow;
}
void Judge(int now){ //  与s一个集合的点
    vis[now]=1;
    for(int i=head[now];i!=-1;i=edge[i].nexts){
        Edge e=edge[i];
        if(!vis[e.to]){
             if(e.flow!=e.cap) Judge(e.to);
         }
    }
}
void Find(int now){ //与t为一个集合的点
    vis[now]=1;
    for(int i=head[now];i!=-1;i=edge[i].nexts){
        Edge e=edge[i];;
        if(!vis[e.to]){
            if(edge[i^1].cap-edge[i^1].flow) Find(e.to);
        }
    }
}

int main(){
    int n,m,A,B;
    while(scanf("%d%d%d%d",&n,&m,&A,&B)!=EOF){
        if(n+m+A+B==0) break;
        init();  int a,b,c;
        while(m--){
            scanf("%d%d%d",&a,&b,&c);
            addedge(a,b,c);
            addedge(b,a,c);
        }

        max_flow(A,B);
        memset(vis,0,sizeof(vis));
        Judge(A); Find(B);
        int flag=1;
        for(int i=1;i<=n;i++){
            if(!vis[i]){
                flag=0; break;
            }
        }

        if(flag) puts("UNIQUE");
        else puts("AMBIGUOUS");
    }
return 0;
}
查看评论

ZOJ-2587 Unique Attack(最小割是否唯一判定)

关于最小割:点击打开链接 #include #include #include #include #include #include #include #include #include #...
  • u014679804
  • u014679804
  • 2015-08-19 12:44:37
  • 228

ZOJ 2587 Unique Attack 判最小割唯一

View Code #include #includestring.h> #include using namespace std; #define maxn 803 #define maxm 1...
  • c3568
  • c3568
  • 2013-08-29 10:36:05
  • 604

ZOJ 2587 Unique Attack 最小割

Unique Attack Time Limit: 5 Seconds      Memory Limit: 32768 KB N supercomputers in the United...
  • budlele
  • budlele
  • 2014-10-07 17:20:11
  • 495

Unique Attack (zoj 2587 判定最小割是否唯一)

题意:判断最小割是否唯一。 参考点击打开链接
  • u014422052
  • u014422052
  • 2015-07-27 09:32:36
  • 527

zoj 2587 Unique Attack 【判断最小割是否唯一】

Unique Attack Time Limit: 5 Seconds      Memory Limit: 32768 KB N supercomputers in the United Sta...
  • chenzhenyu123456
  • chenzhenyu123456
  • 2015-08-28 10:44:24
  • 923

zoj 2587 Unique Attack 判断最小割是否唯一 sap+dfs

N supercomputers in the United States of Antarctica are connected into a network. A network has a si...
  • kongming_acm
  • kongming_acm
  • 2011-09-19 11:32:23
  • 286

zoj 2587 Unique Attack (判断最小割是否唯一)

题意:
  • u012841845
  • u012841845
  • 2014-08-12 09:13:41
  • 424

ZOJ 2587 && ACdream1235 Unique Attack(判断最小割是否唯一)

Unique Attack Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) ...
  • Yasola
  • Yasola
  • 2017-01-14 15:02:59
  • 305

ZOJ 2587 - Unique Attack 最小割,判断割边集是否唯一

题意:                         给了一个无向图以及起点和终点..问最小割边集是否唯一...                题解:                        ...
  • kk303
  • kk303
  • 2013-09-17 13:47:06
  • 1382

ZOJ 2587 Unique Attack 判断最小割是否唯一

Unique Attack Time Limit: 5 Seconds Memory Limit: 32768 KB N supercomputers in the United S...
  • power721
  • power721
  • 2011-09-16 15:19:39
  • 1290
    个人资料
    持之以恒
    等级:
    访问量: 7万+
    积分: 6564
    排名: 4285
    传送门
    最新评论