HDU 2435 - There is a war

原创 2015年11月19日 11:09:19

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需要破坏一些桥,得到原网络的一个割,要使割最小,
即可把每个桥的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; }

版权声明:本文为博主原创文章,未经博主允许不得转载。

There is a war (hdu 2435 最小割+枚举)

题意:n个国家,m条有向边,国家1要去攻打国家n,n想切断1到n的道路来防御,切断每条道路有一定费用,国家1有一个NB魔法,可以建一条新边或者加固一条已有的边,这条边不能被n破坏,现在求 最大化n国花...

hdu 2435 There is a war 最小割

题意:给定一个有向图,A在1点,B在n点。B为了抵制A可以摧毁一些边,但A可以永久加固一条边使得不可摧毁。 A要怎么加固使得B花费的代价最大。 模型: 首先跑一次1->n的最大流...
  • CHCXCHC
  • 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 ...

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

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

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

hdu2435最大流最小割 2014-03-22 我来说两句 来源:hdu2435最大流最小割 收藏 我要投稿 2435 There is a war 题意: 给你一个有...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:HDU 2435 - There is a war
举报原因:
原因补充:

(最多只允许输入30个字)