题意:
给了一个无向图以及起点和终点..问最小割边集是否唯一...
题解:
先跑最大流求最小割..然后从起点开始dfs..对能到达的点标记为1(边的容量非空才能走)...再从终点开始dfs...对能到达的点标记为2(对应的边容量非空才能走)..然后扫描所有的边..若一条边已经满流了..但是其起点或者终点没有被标记到.则说明最小割边集不唯一....
Program:
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<map>
#include<math.h>
#include<queue>
#define MAXN 905
#define MAXM 50005
#define oo 1000000007
#define ll long long
using namespace std;
struct Dinic
{
struct node
{
int c,u,v,next;
}edge[MAXM];
int ne,head[MAXN];
int cur[MAXN], ps[MAXN], dep[MAXN];
void initial()
{
ne=2;
memset(head,0,sizeof(head));
}
void addedge(int u, int v,int c)
{
edge[ne].u=u,edge[ne].v=v,edge[ne].c=c,edge[ne].next=head[u];
head[u]=ne++;
edge[ne].u=v,edge[ne].v=u,edge[ne].c=c,edge[ne].next=head[v];
head[v]=ne++;
}
int MaxFlow(int s,int t)
{
int tr, res = 0;
int i,j,k,f,r,top;
while(1)
{
memset(dep, -1, sizeof(dep));
for(f=dep[ps[0]=s]=0,r=1;f!= r;)
for(i=ps[f++],j=head[i];j;j=edge[j].next)
if(edge[j].c&&dep[k=edge[j].v]==-1)
{
dep[k]=dep[i]+1;
ps[r++]=k;
if(k == t){ f=r; break; }
}
if(dep[t]==-1) break;
memcpy(cur,head,sizeof(cur));
i=s,top=0;
while(1)
{
if(i==t)
{
for(tr=oo,k=0;k<top;k++)
if(edge[ps[k]].c<tr)
tr=edge[ps[f=k]].c;
for(k=0;k<top;k++)
{
edge[ps[k]].c-=tr;
edge[ps[k]^1].c+=tr;
}
i=edge[ps[top=f]].u;
res+= tr;
}
for(j=cur[i];cur[i];j=cur[i]=edge[cur[i]].next)
if(edge[j].c && dep[i]+1==dep[edge[j].v]) break;
if(cur[i]) ps[top++]=cur[i],i=edge[cur[i]].v;
else
{
if(!top) break;
dep[i]=-1;
i=edge[ps[--top]].u;
}
}
}
return res;
}
int mark[MAXN];
void dfs1(int x)
{
mark[x]=1;
for (int k=head[x];k;k=edge[k].next)
if (!mark[edge[k].v] && edge[k].c)
dfs1(edge[k].v);
}
void dfs2(int x)
{
mark[x]=2;
for (int k=head[x];k;k=edge[k].next)
if (!mark[edge[k].v] && edge[k^1].c)
dfs2(edge[k].v);
}
bool getans(int s,int e)
{
int i;
MaxFlow(s,e);
memset(mark,0,sizeof(mark));
dfs1(s),dfs2(e);
for (i=2;i<ne;i++)
if (!edge[i].c && (!mark[edge[i].u] || !mark[edge[i].v]))
return false;
return true;
}
}T;
int main()
{
int n,m,s,e,u,v,c,sum;
while (~scanf("%d%d%d%d",&n,&m,&s,&e) && n)
{
T.initial();
while (m--)
{
scanf("%d%d%d",&u,&v,&c);
T.addedge(u,v,c);
}
if (T.getans(s,e)) printf("UNIQUE\n");
else printf("AMBIGUOUS\n");
}
return 0;
}