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. 【传智播客VIP用户专享】Swift教程最新更新

    (1)[传智播客VIP用户专享]Swift教程最新更新 特地贡献出来忘帮顶!!(传智内部学院给的) http://pan.baidu.com/s/1jGmRRIu    提取码:i11g 相关资料下载 ...

  2. Ylmf_Ghost_Win7_SP1_x64_2017_0113.iso虚拟机安装

    新建虚拟机,将iso镜像配置好,然后开启虚拟机 一开始选择PQ8.05: 找到“作业”菜单---“建立” ,新建一个“主分区”然后点击确定 新建主分区作业之后,如果需要新建其他分区继续进行即可,本例只 ...

  3. IOS算法(二)之选择排序

    选择排序: 每一趟从待排序的数据元素中选出最小(或最大)的一个元素,顺序放在已排好序的数列的最后.直到所有待排序的数据元素排完. 选择排序是不稳定的排序方法. 一. 算法描写叙述 选择排序:比方在一 ...

  4. C#实现动态调用Windows DLL

    调用方法: object obj = WinDllInvoke("Kernel32.dll", "Beep", , }, typeof(void)); 函数代码 ...

  5. 安装eclipse maven插件m2eclipse No repository found containing

    m2eclipse插件是Eclipse的一款Maven插件. 安装m2eclipse插件的步骤例如以下: 启动Eclipse,在菜单条中选择Help,然后选择Install New Software- ...

  6. oc21--super

    // // Phone.h #import <Foundation/Foundation.h> typedef enum { kFlahlightStatusOpen, kFlahligh ...

  7. Path Sum II 总结DFS

    https://oj.leetcode.com/problems/path-sum-ii/ Given a binary tree and a sum, find all root-to-leaf p ...

  8. [Plugin] WEB版一次选择多个文件进行批量上传(swfupload)的解决方案

    URL:http://www.cnblogs.com/chillsrc/archive/2010/02/21/1670594.html 说明:功能完全支持ie和firefox浏览器! 一般的WEB方式 ...

  9. Oracle 11g RAC for LINUX rhel 6.X silent install(静默安装)

    一.前期规划 1.硬件环境 CPU: Intel(R) Xeon(R) CPU E7-4820 v4 @ 2.00GHz  8*10核 内存:512GB OCR:2147*5 MB DATA1:2TB ...

  10. SQLServer 表连接时使用top 1 去除重复数据

    left join SM_SOLine soline on soline.SO=so.ID and soline.DocLineNo=(select MAX(DocLineNo) from SM_SO ...