A - Unique Attack

Time Limit: 6000/3000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
 
 

Problem Description

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 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 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

Sample Output

UNIQUE
AMBIGUOUS 解题:最小割的唯一性判定 利用残量网络,除源汇点外的点,要么可以沿着未满流的弧从源点到达,要么可以到大汇。则唯一,如果存在点,既不能由源点到达,又不去由该点到达汇,则不唯一
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc {
int to,flow,next;
arc(int x = ,int y = ,int z = -) {
to = x;
flow = y;
next = z;
}
};
arc e[maxn*maxn];
int head[maxn],d[maxn],cur[maxn];
int n,m,S,T,tot,src,sink;
void add(int u,int v,int flow) {
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
bool bfs() {
queue<int>q;
memset(d,-,sizeof(d));
d[S] = ;
q.push(S);
while(!q.empty()) {
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i].flow && d[e[i].to] == -) {
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[T] > -;
}
int dfs(int u,int low) {
if(u == T) return low;
int tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next) {
if(e[i].flow && d[e[i].to] == d[u] + && (a=dfs(e[i].to,min(low,e[i].flow)))) {
tmp += a;
low -= a;
e[i].flow -= a;
e[i^].flow += a;
if(!low) break;
}
}
if(tmp == ) d[u] = -;
return tmp;
}
int dinic() {
int tmp = ;
while(bfs()) {
memcpy(cur,head,sizeof(head));
tmp += dfs(S,INF);
}
return tmp;
}
bool vis[maxn];
void dfs1(int u) {
for(int i = head[u]; ~i; i = e[i].next) {
if(!vis[e[i].to] && e[i].flow) {
vis[e[i].to] = true;
dfs1(e[i].to);
}
}
}
void dfs2(int u) {
for(int i = head[u]; ~i; i = e[i].next) {
if(!vis[e[i].to] && e[i^].flow) {
vis[e[i].to] = true;
dfs2(e[i].to);
}
}
}
int main() {
int u,v,w;
while(~scanf("%d %d %d %d",&n,&m,&S,&T)) {
memset(head,-,sizeof(head));
for(int i = tot = ; i < m; i++) {
scanf("%d %d %d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
dinic();
//cout<<dinic()<<endl;
memset(vis,false,sizeof(vis));
vis[S] = vis[T] = true;
dfs1(S);
dfs2(T);
bool flag = true;
for(int i = ; i <= n; i++)
if(!vis[i]) {
flag = false;
break;
}
flag?puts("UNIQUE"):puts("AMBIGUOUS");
}
return ;
}

Acdream A - Unique Attack的更多相关文章

  1. ZOJ2587 Unique Attack(判定最小割唯一性)

    看了题解,自己大概想了下. 最小割唯一的充分必要条件是残量网络中所有点要嘛能从源点floodfill到要嘛能floodfill到汇点. 必要性,这是当然的,因为假设从源点floodfill或者从汇点反 ...

  2. zoj 2587 Unique Attack 最小割判定

    题目链接 让你判断最小割是否唯一. 判断方法是, 先求一遍最大流, 然后从源点dfs一次, 搜索未饱和边的数目. 从汇点dfs一次, 同样也是搜索未饱和边的数目, 看总和是否等于n. 如果等于n那么唯 ...

  3. ZOJ 2587 Unique Attack(最小割唯一性判断)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2587 题意:判断最小割是否唯一. 思路: 最小割唯一性的判断是先跑一遍最大 ...

  4. ZOJ - 2587 Unique Attack (判断最小割是否唯一)

    题意:判断最小割是否唯一. 分析:跑出最大流后,在残余网上从源点和汇点分别dfs一次,对访问的点都打上标记. 若还有点没有被访问到,说明最小割不唯一. https://www.cnblogs.com/ ...

  5. [ZOJ2587]Unique Attack

    vjudge sol 最小割判定唯一性. 只要做完一个任意最小割后,判断一下是不是所有点都要么和\(S\)相连,要么和\(T\)相连. 只要两边各一次\(dfs\)就行了. code #include ...

  6. zoj 2587 Unique Attack【最小割】

    拆点拆魔怔了 直接按照原图建就行,这里有个小技巧就是双向边的话不用按着板子建(u,v,c)(v,u,0)(v,u,c)(u,v,0),直接建(u,v,c)(v,u,c)会快十倍!800ms->8 ...

  7. ZOJ 2587 Unique Attack (最小割唯一性)

    题意 判断一个无向图的割是否唯一 思路 错误思路:一开始想的是判断割边是否都是关键割边,那既然割边两端点能连通S.T点的边是关键边,那么只要遇到有某个边两端点不连通S or T则这条边就不是关键割边( ...

  8. [转] POJ图论入门

    最短路问题此类问题类型不多,变形较少 POJ 2449 Remmarguts' Date(中等)http://acm.pku.edu.cn/JudgeOnline/problem?id=2449题意: ...

  9. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

随机推荐

  1. 新建maven web工程报错

    问题: 检查本地仓库: 检查1.0跟release的文件夹: 试试:http://www.ithao123.cn/content-8028507.html 然后选择maven catalog下的:(这 ...

  2. Linux 下的时间编程总结

    在嵌入式编程中中.常常须要输出系统的当前时间.计算程序的运行时间.使用计时器等.近期也做了不少关于时间的操作.今天就认真总结一下,部分内容是在网上看到的.自己经过验证总结出来. 1.时间的类型 1.格 ...

  3. Android 怎样实现 焦点图的 无线循环滑动的状态?

    參考网址:http://my.oschina.net/xsk/blog/119167 总体的架构:ViewPgaer 中直接嵌套  IamgeView 方案一:  重写Viewpager 这样有局限性 ...

  4. UVa 572 - Oil Deposits (简单dfs)

    Description GeoSurvComp地质调查公司负责探測地下石油储藏. GeoSurvComp如今在一块矩形区域探測石油.并把这个大区域分成了非常多小块.他们通过专业设备.来分析每一个小块中 ...

  5. php创建简单的列表页

    php创建简单的列表页 样例 代码 <?php $userInfo[] = array( 'id'=>'1', 'username'=>'fry', 'sex'=>'nan', ...

  6. Quartz实例:quartz定时任务代码示例

    转自:http://www.blogchong.com/post/96.html quartz定时任务调度框架,使用实例. Job类://即实际调度任务实现 . package net.csdn.ed ...

  7. js重定向

    在现行的网站应用中URL重定向的应用有很多: 404页面处理.网址改变(t.sina转到weibo.com).多个网站地址(如:http://www.google.com/ .www.g.cn )等: ...

  8. RecyclerView实现终极画廊效果 中间突出并且压住两侧布局

    先给大家上个gif 要不然下面很枯燥 忘记原来在哪里看到了..... 这个效果我找了NNNNNN长时间,,,我认为凭我现在的能力 写出来需要好久 所以 退而求其次找大神写好的... 你们不要小看了这个 ...

  9. python3爬虫:下载网易云音乐排行榜

    #!/usr/bin/python3# -*- encoding:utf-8 -*- # 网易云音乐批量下载 import requestsimport urllib # 榜单歌曲批量下载# r = ...

  10. Redis 四:存储类型之散列类型

    1.散列类型表达方式简介: =========================================== 键 字段 值 =================================== ...