There is a war

Time Limit: 1000ms
Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 2435
64-bit integer IO format: %I64d      Java class name: Main

There is a sea.
There are N islands in the sea.
There are some directional bridges connecting these islands.
There is a country called Country One located in Island 1.
There is another country called Country Another located in Island N.
There is a war against Country Another, which launched by Country One.
There
is a strategy which can help Country Another to defend this war by
destroying the bridges for the purpose of making Island 1 and Island n
disconnected.
There are some different destroying costs of the bridges.
There
is a prophet in Country Another who is clever enough to find the
minimum total destroying costs to achieve the strategy.
There
is an architecture in Country One who is capable enough to rebuild a
bridge to make it unbeatable or build a new invincible directional
bridge between any two countries from the subset of island 2 to island
n-1.
There is not enough time for Country One, so it can only
build one new bridge, or rebuild one existing bridge before the Country
Another starts destroying, or do nothing if happy.
There is a
problem: Country One wants to maximize the minimum total destroying
costs Country Another needed to achieve the strategy by making the best
choice. Then what’s the maximum possible result?

Input

There are multiple cases in this problem.
There is a line with an integer telling you the number of cases at the beginning.
The
are two numbers in the first line of every case, N(4<=N<=100) and
M(0<=M<=n*(n-1)/2), indicating the number of islands and the
number of bridges.
There are M lines following, each one of
which contains three integers a, b and c, with 1<=a, b<=N and
1<=c<=10000, meaning that there is a directional bridge from a to b
with c being the destroying cost.
There are no two lines containing the same a and b.

Output

There is one line with one integer for each test case, telling the maximun possible result.

Sample Input

4
4 0
4 2
1 2 2
3 4 2
4 3
1 2 1
2 3 1
3 4 10
4 3
1 2 5
2 3 2
3 4 3

Sample Output

0
2
1
3

Source

 
解题:暴力枚举 + 最小割
 #include <bits/stdc++.h>
using namespace std;
const int INF = ~0U>>;
const int maxn = ;
struct arc {
int to,flow,next;
arc(int x = ,int y = ,int z = -) {
to = x;
flow = y;
next = z;
}
} e[maxn*maxn];
int head[maxn],d[maxn],gap[maxn],tot,S,T;
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++;
}
int dfs(int u,int low) {
if(u == T) return low;
int tmp = ,minH = T - ;
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i].flow) {
if(d[u] == d[e[i].to] + ) {
int a = dfs(e[i].to,min(e[i].flow,low));
e[i].flow -= a;
e[i^].flow += a;
tmp += a;
low -= a;
if(!low) break;
if(d[S] >= T) return tmp;
}
}
if(e[i].flow) minH = min(minH,d[e[i].to]);
}
if(!tmp) {
if(--gap[d[u]] == ) d[S] = T;
++gap[d[u] = minH + ];
}
return tmp;
}
int sap(int ret = ) {
memset(gap,,sizeof gap);
memset(d,,sizeof d);
gap[S] = T;
while(d[S] < T) ret += dfs(S,INF);
return ret;
}
bool vis[maxn];
void dfs(int u) {
vis[u] = true;
for(int i = head[u]; ~i; i = e[i].next)
if(e[i].flow && !vis[e[i].to]) dfs(e[i].to);
}
int a[maxn*maxn],b[maxn*maxn],c[maxn*maxn];
int main() {
int n,m,kase;
scanf("%d",&kase);
while(kase--) {
scanf("%d%d",&n,&m);
memset(head,-,sizeof head);
for(int i = tot = ; i < m; ++i) {
scanf("%d%d%d",a + i,b + i,c + i);
add(a[i],b[i],c[i]);
}
S = ;
T = n;
int ret = sap();
memset(vis,false,sizeof vis);
dfs(S);
for(int i = ; i < n; ++i) {
if(!vis[i]) continue;
for(int j = ; j < n; ++j) {
if(vis[j]) continue;
memset(head,-,sizeof head);
for(int k = tot = ; k < m; ++k)
add(a[k],b[k],c[k]);
add(i,j,INF);
ret = max(ret,sap());
}
}
printf("%d\n",ret);
}
return ;
}

HDU 2435 There is a war的更多相关文章

  1. HDU 2435 There is a war (网络流-最小割)

    There is a war Problem Description       There is a sea.       There are N islands in the sea.       ...

  2. HDU 2435 There is a war Dinic 最小割

    题意是有n座城市,n号城市不想让1号城市可达n号,每条道路有一条毁坏的代价,1号还可以修一条不能毁坏的道路,求n号城市所需的最小代价最大是多少. 毁坏的最小代价就直接求一遍最大流,就是最小割了.而可以 ...

  3. hdu 2435 dinic算法模板+最小割性质

    #include<stdio.h> #include<queue> #include<string.h> using namespace std; #define ...

  4. hdu 2435dinic算法模板+最小割性质

    hdu2435最大流最小割 2014-03-22 我来说两句 来源:hdu2435最大流最小割 收藏 我要投稿 2435 There is a war 题意: 给你一个有向图,其中可以有一条边是无敌的 ...

  5. hdu2435最大流最小割

    2435  There is a war 题意:       给你一个有向图,其中可以有一条边是无敌的,这条边可以是图中的边,也可以是自己任意加上去的图中没有的边,这条无敌的边不可以摧毁,让1和n无法 ...

  6. hdu 4005 The war

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4005 In the war, the intelligence about the enemy is ...

  7. War Chess (hdu 3345)

    http://acm.hdu.edu.cn/showproblem.php?pid=3345 Problem Description War chess is hh's favorite game:I ...

  8. HDU 4005 The war(双连通好题)

    HDU 4005 The war pid=4005" target="_blank" style="">题目链接 题意:给一个连通的无向图.每条 ...

  9. HDU 4005 The war Tarjan+dp

    The war Problem Description   In the war, the intelligence about the enemy is very important. Now, o ...

随机推荐

  1. Navicate Premium连接Oracle数据库报错

    Navicat Premium连接MySQL数据库没有问题,在连接Oracle数据库的时候报错,提示:ORA-28547:connection to server failed,probable Or ...

  2. 寻找最美的你(select)

    Time Limit:2000ms   Memory Limit:128MB 题目描述 这个问题是这样的,如果一个区间[L,R]存在一个数ai,使得这个数是这个区间所有数的约数,那么[L,R]这段区间 ...

  3. iOS 常用手势

    UIGestureRecognizer 对iOS的各种手势进行了封装,完全满足了用户对手势的需求. 以下是对各种手势的详细应用和说明,希望能对大家有帮助.^_^ - (void)viewDidLoad ...

  4. idea npm 调试报错解决办法

    1.用egg框架的开发时候,egg 提供本地开发和调试.点击idea 的debug 按钮时候报如下错误: Please specify npm or yarn package: cannot find ...

  5. EJB2.0教程 详解EJB技术及实现原理

    EJB是什么呢?EJB是一个J2EE体系中的组件.再简单的说它是一个能够远程调用的javaBean.它同普通的javaBean有两点不同.第一点,就是远程调用.第二点,就是事务的功能,我们在EJB中声 ...

  6. LINUX 安装JDK (rpm格式和tar.gz格式)

    谷歌博客地址:http://tsaiquinn.blogspot.com/2014/10/linux-jdk-rpmtargz.html JDK rpm方式: 我使用的是SecureCRT,先下载了然 ...

  7. Codeforces A ACM (ACronym Maker) (dp)

    http://codeforces.com/gym/100650 概要:给出一个缩写,和一些单词,从单词中按顺序选一些字母作为缩写,问方案数. 限制:某些单词要忽略,每个单词至少要选一个字母. dp[ ...

  8. js parse_url 引发的

    原文链接:https://www.w3.org/TR/2011/WD-html5-20110525/origin-0.html 这里只是做下记录: 5.3 Origin — HTML5 li, dd ...

  9. linx vim 文件操作 ubuntu server 软件源

    mv /etc/danted.conf /etc/danted.conf.bak sudo wget https://files.cnblogs.com/files/marklove/danted.t ...

  10. 利用VS自带的命令行工具查看和生产PublicKeyToken

    使用VS2008(或其他版本)命令行工具,键入:SN -T C:\*****.dll 就会显示出该dll具体的PublicKeyToken数值. 如果该程序集没有强命 名,则不会有PublicKeyT ...