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. 第5章 引用类型---JS红宝书书摘系列笔记

    在ECMAScript中,引用类型是一种数据结构,用于将数据和功能组织在一起,描述的是一类对象所具有的属性和方法.而对象是某个特定引用类型的实例. 一.Object类型 可以通过Object构造函数创 ...

  2. 国内的Jquery CDN免费服务

    Jquery是个非常流行的JS前端框架,在很多网站都能看到它的身影.很多网站都喜欢采用一些Jquery CDN加速服务,这样网站加载jquery会更快.之前火端网络的一些网站都是使用Google的jq ...

  3. 基于eclipse搭建android开发环境-win7 32bit

    基于eclipse搭建android开发环境-win7 32bit 前言:在使用朋友已搭建的Android开发环境时,发现朋友的开发环境版本较低且在update SDk时失败,便决定根据网上文章提示从 ...

  4. SVN客户端--TortoiseSVN使用说明

    TortoiseSVN是windows下其中一个非常优秀的SVN客户端工具.通过使用它,我们可以可视化的管理我们的版本库.不过由于它只是一个客户端,所以它不能对版本库进行权限管理. TortoiseS ...

  5. 洛谷 P1376 机器工厂

    题目描述 小T开办了一家机器工厂,在N(N<=10000)个星期内,原材料成本和劳动力价格不断起伏,第i周生产一台机器需要花费Ci(1<=Ci<=5000)元.若没把机器卖出去,每保 ...

  6. More helpful Cocos2d and Gaming macros

    More helpful Cocos2d and Gaming macros Here are w few macros that i wrote to make the code more read ...

  7. java 核心技术卷一笔记 6 .2接口 lambda 表达式 内部类

    6.2 接口实例 6.2.1 接口与回调 在java.swing包中有一个Timer类,可以使用它在到达给定的时间间隔时发出通告,假如程序中有一个时钟,就可以请求每秒钟获得一个通告,以便更新时钟的表盘 ...

  8. MVC 学习小总结

    一般情况下新增字段首选现在数据库更新,然后再从数据库更新模型 第二选择是从模板添加字段更新数据库(面临删除所有数据可能,慎用) 第三是没有T4模板的前提下再模型完成操作然后修改model类防止mode ...

  9. UVA 1220 Party at Hali-Bula (树形DP)

    求一棵数的最大独立集结点个数并判断方案是否唯一. dp[i][j]表示以i为根的子树的最大独立集,j的取值为选和不选. 决策: 当选择i时,就不能选择它的子结点. 当不选i时,它的子结点可选可不选. ...

  10. python_113_socket编程

    Socket语法及相关 socket概念 socket本质上就是在2台网络互通的电脑之间,架设一个通道,两台电脑通过这个通道来实现数据的互相传递. 我们知道网络 通信 都 是基于 ip+port 方能 ...