博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Acdream A - Unique Attack
阅读量:5023 次
发布时间:2019-06-12

本文共 4513 字,大约阅读时间需要 15 分钟。

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 21 2 12 4 21 3 23 4 14 4 1 21 2 12 4 11 3 23 4 1

Sample Output

UNIQUEAMBIGUOUS 解题:最小割的唯一性判定 利用残量网络,除源汇点外的点,要么可以沿着未满流的弧从源点到达,要么可以到大汇。则唯一,如果存在点,既不能由源点到达,又不去由该点到达汇,则不唯一
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #define LL long long 14 #define INF 0x3f3f3f3f 15 using namespace std; 16 const int maxn = 810; 17 struct arc { 18 int to,flow,next; 19 arc(int x = 0,int y = 0,int z = -1) { 20 to = x; 21 flow = y; 22 next = z; 23 } 24 }; 25 arc e[maxn*maxn]; 26 int head[maxn],d[maxn],cur[maxn]; 27 int n,m,S,T,tot,src,sink; 28 void add(int u,int v,int flow) { 29 e[tot] = arc(v,flow,head[u]); 30 head[u] = tot++; 31 e[tot] = arc(u,0,head[v]); 32 head[v] = tot++; 33 } 34 bool bfs() { 35 queue
q; 36 memset(d,-1,sizeof(d)); 37 d[S] = 1; 38 q.push(S); 39 while(!q.empty()) { 40 int u = q.front(); 41 q.pop(); 42 for(int i = head[u]; ~i; i = e[i].next) { 43 if(e[i].flow && d[e[i].to] == -1) { 44 d[e[i].to] = d[u] + 1; 45 q.push(e[i].to); 46 } 47 } 48 } 49 return d[T] > -1; 50 } 51 int dfs(int u,int low) { 52 if(u == T) return low; 53 int tmp = 0,a; 54 for(int &i = cur[u]; ~i; i = e[i].next) { 55 if(e[i].flow && d[e[i].to] == d[u] + 1 && (a=dfs(e[i].to,min(low,e[i].flow)))) { 56 tmp += a; 57 low -= a; 58 e[i].flow -= a; 59 e[i^1].flow += a; 60 if(!low) break; 61 } 62 } 63 if(tmp == 0) d[u] = -1; 64 return tmp; 65 } 66 int dinic() { 67 int tmp = 0; 68 while(bfs()) { 69 memcpy(cur,head,sizeof(head)); 70 tmp += dfs(S,INF); 71 } 72 return tmp; 73 } 74 bool vis[maxn]; 75 void dfs1(int u) { 76 for(int i = head[u]; ~i; i = e[i].next) { 77 if(!vis[e[i].to] && e[i].flow) { 78 vis[e[i].to] = true; 79 dfs1(e[i].to); 80 } 81 } 82 } 83 void dfs2(int u) { 84 for(int i = head[u]; ~i; i = e[i].next) { 85 if(!vis[e[i].to] && e[i^1].flow) { 86 vis[e[i].to] = true; 87 dfs2(e[i].to); 88 } 89 } 90 } 91 int main() { 92 int u,v,w; 93 while(~scanf("%d %d %d %d",&n,&m,&S,&T)) { 94 memset(head,-1,sizeof(head)); 95 for(int i = tot = 0; i < m; i++) { 96 scanf("%d %d %d",&u,&v,&w); 97 add(u,v,w); 98 add(v,u,w); 99 }100 dinic();101 //cout<
<
View Code

 

转载于:https://www.cnblogs.com/crackpotisback/p/4009511.html

你可能感兴趣的文章
【最小生成树】Connect the Cities
查看>>
现代软件与游戏的创新性分析
查看>>
C# DataTable下载
查看>>
ES6之map
查看>>
下拉插件dropload js时间计算(几天前)
查看>>
外部类监听发送短信--------------------------setOnLongClickListener------------------------
查看>>
JQuery-遮罩层
查看>>
【luogu P3371 单源最短路径】 模板 dij + heap
查看>>
(五)数据类型转换
查看>>
练习1--选老大问题
查看>>
简单研究Android View绘制三 布局过程
查看>>
红黑树(中序二叉树)
查看>>
Android Studio 运行出现 Multiple dex files define Landroid/support/annotation/AnimRes 解决方法...
查看>>
有关并查集的emmmm
查看>>
P1022 计算器的改良
查看>>
文件上传解析漏洞
查看>>
多线程频繁写全局变量导致性能降低
查看>>
移动端适配
查看>>
android 控件 显示 隐藏
查看>>
eclipse 默认 utf-8
查看>>