HDU 2435 - There is a war
来源:互联网 发布:襄阳网站搜索引擎优化 编辑:程序博客网 时间:2024/05/17 08:23
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?
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.
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
44 04 21 2 23 4 24 31 2 12 3 13 4 104 31 2 52 3 23 4 3
Sample Output
0213
Solution
①首先,我们知道如果A没有修桥,则B需要破坏一些桥,得到原网络的一个割,要使割最小,即可把每个桥的cost看成容量,求出最大流;②现在问题是修桥以后的,那么,假设现在已经完成了第一步,得到原网络的两个分量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;}
0 0
- HDU 2435 There is a war
- HDU 2435 - There is a war
- hdu 2435 There is a war 最小割-带加边条件
- hdu 2435 There is a war 最小割
- There is a war (hdu 2435 最小割+枚举)
- HDU 2435 There is a war Dinic 最小割
- HDU 2435 There is a war (网络流-最小割)
- HDU 2435 There is a war(修改或添加一条边的最小割 )经典
- HDOJ 2435 - There is a war 枚举+最小割
- Sicily 1906. There is a war
- there is a reason
- louboutin homme pas cher there is a war drama shot injured
- HDU2435 There is a war 修改一条边权值后的最小割
- hdoj 2435 There is a war 【求原图最小割已经分成的两个点集 + 枚举两点集里面的点建新边 求残量网络的最大最小割】
- Where there is a will,there is a way...
- Where there is a will, there is a way
- There is a board with
- where there is internet ,there is a way
- Valid Parentheses
- 有了这个列表,程序员不愁没练手的小项目了
- 基于模板匹配和遗传算法的人眼定位
- redis-cli 命令总结(转)
- PHP与Redis开发环境的简单配置
- HDU 2435 - There is a war
- 我的第一篇博客
- Android中判断网络连接是否可用及监控网络状态
- FAL[server, ARC3]: FAL archive failed Error 16401 creating standby archive log file at host
- How Did Watson Answer? —— Relation Extraction
- 交换两个变量的内容
- 关于unity中支持的音频的格式和视频的格式的总结
- shrio配置
- PHP中die和exit的区别