Acdream A - Unique Attack
A - Unique Attack
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
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的更多相关文章
- ZOJ2587 Unique Attack(判定最小割唯一性)
看了题解,自己大概想了下. 最小割唯一的充分必要条件是残量网络中所有点要嘛能从源点floodfill到要嘛能floodfill到汇点. 必要性,这是当然的,因为假设从源点floodfill或者从汇点反 ...
- zoj 2587 Unique Attack 最小割判定
题目链接 让你判断最小割是否唯一. 判断方法是, 先求一遍最大流, 然后从源点dfs一次, 搜索未饱和边的数目. 从汇点dfs一次, 同样也是搜索未饱和边的数目, 看总和是否等于n. 如果等于n那么唯 ...
- ZOJ 2587 Unique Attack(最小割唯一性判断)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2587 题意:判断最小割是否唯一. 思路: 最小割唯一性的判断是先跑一遍最大 ...
- ZOJ - 2587 Unique Attack (判断最小割是否唯一)
题意:判断最小割是否唯一. 分析:跑出最大流后,在残余网上从源点和汇点分别dfs一次,对访问的点都打上标记. 若还有点没有被访问到,说明最小割不唯一. https://www.cnblogs.com/ ...
- [ZOJ2587]Unique Attack
vjudge sol 最小割判定唯一性. 只要做完一个任意最小割后,判断一下是不是所有点都要么和\(S\)相连,要么和\(T\)相连. 只要两边各一次\(dfs\)就行了. code #include ...
- zoj 2587 Unique Attack【最小割】
拆点拆魔怔了 直接按照原图建就行,这里有个小技巧就是双向边的话不用按着板子建(u,v,c)(v,u,0)(v,u,c)(u,v,0),直接建(u,v,c)(v,u,c)会快十倍!800ms->8 ...
- ZOJ 2587 Unique Attack (最小割唯一性)
题意 判断一个无向图的割是否唯一 思路 错误思路:一开始想的是判断割边是否都是关键割边,那既然割边两端点能连通S.T点的边是关键边,那么只要遇到有某个边两端点不连通S or T则这条边就不是关键割边( ...
- [转] POJ图论入门
最短路问题此类问题类型不多,变形较少 POJ 2449 Remmarguts' Date(中等)http://acm.pku.edu.cn/JudgeOnline/problem?id=2449题意: ...
- Soj题目分类
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...
随机推荐
- 【cl】selenium实例2:打开百度,输入hello world
/*创建的类为junit class*/ package Selenium_lassen; import static org.junit.Assert.*; import java.io.File; ...
- Head First 设计模式 —— 装饰器模式
1. 装饰器模式与继承 与装饰器模式相比,继承更容易造成类爆炸: 装饰器模式:利用组合取代继承:
- Spring SSM 框架
IDEA 整合 SSM 框架学习 http://www.cnblogs.com/wmyskxz/p/8916365.html 认识 Spring 框架 更多详情请点击这里:这里 Spring 框架是 ...
- 记录,javascript中对象的属性名是字符串,却可以不用引号
问题描述:今日看书,里面介绍js的对象的属性名是包括空字符串在内的所以字符串 问题来了,我们平时定义的对象如下,是没有引号""or’'的 var someone = { f ...
- flex和layout移动端布局
1.九宫格 样式为: ul{ display: flex; flex-wrap: wrap;//超出换行 } li{ width: 33%; height: 60px; display: flex; ...
- 3.ThinkPHP入门---视图
视图:MVC三大组成部分,负责信息的展示和输出 1.视图的创建 创建的位置需要是在分组目录下的view目录下余控制器同名的目录中. 2.视图的展示 在smarty和tinkphp都是使用diaplay ...
- Tomcat修改默认根目录
tomcat7默认的程序发布路径为tomcat/webapps/ROOT/下面 修改Tomcat配置文件server.xml <Host name="localhost" a ...
- JavaScript操作HTML&CSS简单入门
- Java攻城狮学习路线 - 一. JavaScript基础 输出 使用 window.alert() 弹出警告框. 使用 document.write() 方法将内容写到 HTML 文档中. 使用 ...
- Fiddler-AutoResponder 修改接口数据
问题 App 功能测试时,有些场景需要特殊的数据,如 App 对极限值的处理:或是账单列表的时间需要显示刚刚.昨天.周几,需要接口返回不同的时间.更改数据库是一种方法,但不够灵活,一些复杂的场景也不好 ...
- 关于CommandTimeOut
指示在终止尝试和产生错误之前执行命令期间需等待的时间. 设置和返回值 设置或返回长整型值,该值指示等待命令执行的时间(单位为秒).默认值为 30. 说明 Connection 对象或Command 上 ...