# HDU 2435 - There is a war

Description

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

Solution

①首先，我们知道如果A没有修桥，则B需要破坏一些桥，得到原网络的一个割，要使割最小，

②现在问题是修桥以后的，那么，假设现在已经完成了第一步，得到原网络的两个分量P,Q，要修桥一定不会选择同在

③现在已经知道了，桥只能修在P，Q中间，修好桥后，这个桥的容量应该是无穷大(不可摧毁)，要考虑的就是桥要

④剩下的已经很好考虑了。。。

#include<cstdio> #include<vector> #include<queue> #include<cstring> #include<algorithm> using namespace std; const int N = 100 + 1; const int M = N * N; const int INF = 1 << 30; struct E { int v, c, f; E(int v, int c) { this->v = v; this->c = c; f = 0; } }; vector<int> G[N]; int C[N][N], F[N][N]; int able[N], p[N]; queue<int> q; int folkson(const int s, const int t) { int res = 0; while(true) { memset(able, 0, sizeof(able)); able[s] = INF; q.push(s); p[s] = s; while(!q.empty()) { int u = q.front(); q.pop(); for(int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if(able[v] == 0 && F[u][v] < C[u][v]) { able[v] = min(able[u], C[u][v] - F[u][v]); q.push(v); p[v] = u; } } } if(able[t] == 0) break; for(int u = t; u != s; u = p[u]) { F[p[u]][u] += able[t]; F[u][p[u]] -= able[t]; } res += able[t]; } return res; } inline void trans(const int s, const int t) { for(int i = s; i <= t; i++) { for(int j = i; j <= t; j++) { swap(F[i][j], F[j][i]); swap(C[i][j], C[j][i]); } } } int solve(const int s, const int t) { int res = folkson(s, t); int maxa = 0, maxb = 0; folkson(s, t); for(int i = 2; i < t; i++) maxa = max(maxa, able[i]); trans(s, t); folkson(t, s); for(int i = 2; i < t; i++) maxb = max(maxb, able[i]); res += min(maxa, maxb); return res; } inline void initialize() { memset(F, 0, sizeof(F)); memset(C, 0, sizeof(C)); for(int i = 1; i < N; i++) G[i].clear(); } int main() { int T; int n, m; scanf("%d", &T); while( T-- ) { initialize(); scanf("%d%d", &n, &m); for(int i = 0; i < m; i++) { int u, v, c; scanf("%d%d%d", &u, &v, &c); C[u][v] = c; G[u].push_back(v); G[v].push_back(u); } printf("%d\n", solve(1, n)); } return 0; }

• 本文已收录于以下专栏：

## hdu 2435 There is a war 最小割

• CHCXCHC
• 2014年12月02日 22:04
• 426

## hdu 2435 There is a war 最小割-带加边条件

/* 题意：给定一个有向网络，边权为拆掉边的代价，现在1要到n去，n试图阻止1到底，它至少花多大代价。 有一个条件，1可以在任意两点（不含1和n）加入一条边（此边不可被拆除），求n要花费的...

## hdoj 2435 There is a war 【求原图最小割已经分成的两个点集 + 枚举两点集里面的点建新边 求残量网络的最大最小割】

There is a war Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T...

## louboutin homme pas cher there is a war drama shot injured

,louboutin homme pas cher lumbar transverse process fractures, lying in bed three months, my whole ...

## Displays a rotatable and animateable (if there is such a wor

• 2006年02月23日 09:05
• 62KB
• 下载

## Show Message When There is No Disk in a Drive

• 2006年02月23日 09:05
• 1KB
• 下载

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

#include #include #include using namespace std; #define inf 0x3fffffff #define N 200 struct node { i...

## This is an excellent example of image processing. There are

• 2006年02月23日 09:05
• 161KB
• 下载

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

hdu2435最大流最小割 2014-03-22 我来说两句 来源：hdu2435最大流最小割 收藏 我要投稿 2435 There is a war 题意: 给你一个有...

举报原因： 您举报文章：HDU 2435 - There is a war 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)