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. jQuery测试

    1.在div元素中,包含了一个<span>元素,通过has选择器获取<div>元素中的<span>元素的语法是? 提示使用has() $("div&quo ...

  2. WebService学习之旅(七)Axis2发布WebService的几种方式

    前面几篇文章中简单的介绍了如何使用Axis2发布WebService及如何使用Axis2实现Web服务的客户端调用,本节將详细介绍Axis2发布WebService的几种方式. 一.使用aar包方式发 ...

  3. POJ 2955 Brackets (区间DP,常规)

    题意: 给出一个字符串,其中仅仅含 “ ( ) [ ] ” 这4钟符号,问最长的合法符号序列有多长?(必须合法的配对,不能混搭) 思路: 区间DP的常规问题吧,还是枚举区间[i->j]再枚举其中 ...

  4. EL1008E: Property or field 'timestamp' cannot be found on object of type 'java.util.HashMap

    2018-06-22 09:50:19.488  INFO 20096 --- [nio-8081-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : ...

  5. SAP Cloud for Customer(C4C)的一些学习资料

    经常有顾问朋友们问我想自学C4C,有什么好的资料. SAP内部确实有一些C4C培训材料,但是不能散布到公司外部. 想学习C4C,还是得到SAP官网网站上查找资料. 1. 登录https://help. ...

  6. make 与makefile(会不会写 makefile,从一个侧面说明了一个人是否具备完成大型工程的能力。)

    跟我一起写 Makefile /**/ 陈皓 (CSDN) 概述 —— 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉 ...

  7. Educational Codeforces Round 11 C hard process_补题——作为司老大的脑残粉

    司老大当时教了一种姿势枚举连续K个0,说实话当时比赛写这题完全蒙了 纵然后来知道思路还是写了一段时间 真的是.. 题目大意 n长度的序列,由0 1构成 我们可以改变 k个0为1 求可以得到的最长连续1 ...

  8. 什么是闭包(Closure)?

    http://kb.cnblogs.com/page/111780/ 这个问题是在最近一次英格兰Brighton ALT.NET Beers活动中提出来的.我发现,如果不用代码来演示,你很难单用话语把 ...

  9. firstElectron_web5 安装

    小娜 搜 cmd 右键 管理员运行 1.装全局 这样 不用每次都下载 因为包挺大的 还有用cnpm 要不太慢 cnpm install electron --save-dev --save-exact ...

  10. java导入Excel表格数据

    首先导入Excel数据需要几样东西 第一需要两个依赖包,这里直接是在pom注入依赖 <!--excel--> <dependency> <groupId>org.a ...