【HDU】3987 Harry Potter and the Forbidden Forest 最小割
来源:互联网 发布:设计店铺的软件 编辑:程序博客网 时间:2024/05/16 19:06
Harry Potter and the Forbidden Forest
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1335 Accepted Submission(s): 455
Problem Description
Harry Potter notices some Death Eaters try to slip into Castle. The Death Eaters hide in the most depths of Forbidden Forest. Harry need stop them as soon as.
The Forbidden Forest is mysterious. It consists of N nodes numbered from 0 to N-1. All of Death Eaters stay in the node numbered 0. The position of Castle is node n-1. The nodes connected by some roads. Harry need block some roads by magic and he want to minimize the cost. But it’s not enough, Harry want to know how many roads are blocked at least.
The Forbidden Forest is mysterious. It consists of N nodes numbered from 0 to N-1. All of Death Eaters stay in the node numbered 0. The position of Castle is node n-1. The nodes connected by some roads. Harry need block some roads by magic and he want to minimize the cost. But it’s not enough, Harry want to know how many roads are blocked at least.
Input
Input consists of several test cases.
The first line is number of test case.
Each test case, the first line contains two integers n, m, which means the number of nodes and edges of the graph. Each node is numbered 0 to n-1.
Following m lines contains information about edges. Each line has four integers u, v, c, d. The first two integers mean two endpoints of the edges. The third one is cost of block the edge. The fourth one means directed (d = 0) or undirected (d = 1).
Technical Specification
1. 2 <= n <= 1000
2. 0 <= m <= 100000
3. 0 <= u, v <= n-1
4. 0 < c <= 1000000
5. 0 <= d <= 1
The first line is number of test case.
Each test case, the first line contains two integers n, m, which means the number of nodes and edges of the graph. Each node is numbered 0 to n-1.
Following m lines contains information about edges. Each line has four integers u, v, c, d. The first two integers mean two endpoints of the edges. The third one is cost of block the edge. The fourth one means directed (d = 0) or undirected (d = 1).
Technical Specification
1. 2 <= n <= 1000
2. 0 <= m <= 100000
3. 0 <= u, v <= n-1
4. 0 < c <= 1000000
5. 0 <= d <= 1
Output
For each test case:
Output the case number and the answer of how many roads are blocked at least.
Output the case number and the answer of how many roads are blocked at least.
Sample Input
34 50 1 3 00 2 1 01 2 1 11 3 1 12 3 3 16 70 1 1 00 2 1 00 3 1 01 4 1 02 4 1 03 5 1 04 5 2 03 60 1 1 00 1 2 01 1 1 11 2 1 01 2 1 02 1 1 1
Sample Output
Case 1: 3Case 2: 2Case 3: 2
Author
aMR @ WHU
Source
2011 Multi-University Training Contest 15 - Host by WHU
传送门:【HDU】3987 Harry Potter and the Forbidden Forest
题目大意:求割边最少的最小割。
题目分析:将容量乘上一个比较大的常数并加一来代替原来的容量,这样跑出来的最大流除以常数就是最小割容量,对常数取模就是最少割边数。
代码如下:
传送门:【HDU】3987 Harry Potter and the Forbidden Forest
题目大意:求割边最少的最小割。
题目分析:将容量乘上一个比较大的常数并加一来代替原来的容量,这样跑出来的最大流除以常数就是最小割容量,对常数取模就是最少割边数。
代码如下:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std ;#define RPEF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define clear( a , x ) memset ( a , x , sizeof a )#define copy( a , x ) memcpy ( a , x , sizeof a )typedef long long LL ;const int MAXN = 1005 ;const int MAXE = 1000000 ;const int MAXQ = 1000000 ;const LL INF = 1e15 ;struct Edge {int v , n ;LL c ;Edge ( int var = 0 , LL cap = 0 , int next = 0 ) :v ( var ) , c ( cap ) , n ( next ) {}} ;struct netWork {Edge edge[MAXE] ;int adj[MAXN] , cntE ;int cur[MAXN] , d[MAXN] , num[MAXN] , pre[MAXN] ;bool vis[MAXN] ;int Q[MAXQ] , head , tail ;int s , t , nv ;LL flow ;void init () {cntE = 0 ;clear ( adj , -1 ) ;}void addedge ( int u , int v , LL c , LL rc = 0 ) {edge[cntE] = Edge ( v , c , adj[u] ) ;adj[u] = cntE ++ ;edge[cntE] = Edge ( u , rc , adj[v] ) ;adj[v] = cntE ++ ;}void rev_Bfs () {clear ( vis , 0 ) ;clear ( num , 0 ) ;d[t] = 0 ;vis[t] = 1 ;head = tail = 0 ;Q[tail ++] = t ;num[0] = 1 ;while ( head != tail ) {int u = Q[head ++] ;for ( int i = adj[u] ; ~i ; i = edge[i].n ) {int v = edge[i].v ;if ( vis[v] )continue ;vis[v] = 1 ;d[v] = d[u] + 1 ;++ num[d[v]] ;Q[tail ++] = v ;}}}LL ISAP () {copy ( cur , adj ) ;rev_Bfs () ;flow = 0 ;int i , u = pre[s] = s ;while ( d[s] < nv ) {if ( u == t ) {LL f = INF ;int pos ;for ( i = s ; i != t ; i = edge[cur[i]].v )if ( f > edge[cur[i]].c )f = edge[cur[i]].c , pos = i ;for ( i = s ; i != t ; i = edge[cur[i]].v )edge[cur[i]].c -= f , edge[cur[i] ^ 1].c += f ;u = pos ;flow += f ;}for ( i = cur[u] ; ~i ; i = edge[i].n )if ( edge[i].c && d[u] == d[edge[i].v] + 1 )break ;if ( ~i ) {cur[u] = i ;pre[edge[i].v] = u ;u = edge[i].v ;}else {if ( 0 == ( -- num[d[u]] ) )break ;int mmin = nv ;for ( i = adj[u] ; ~i ; i = edge[i].n )if ( edge[i].c && mmin > d[edge[i].v] )cur[u] = i , mmin = d[edge[i].v] ;d[u] = mmin + 1 ;++ num[d[u]] ;u = pre[u] ;}}return flow ;}} ;netWork net ;int read () {char c = ' ' ;int x = 0 ;while ( c < '0' || c > '9' )c = getchar () ;while ( c >= '0' && c <= '9' ) {x = x * 10 + c - '0' ;c = getchar () ;}return x ;}void work () {int n , m ;int d , u , v , c ;net.init () ;n = read () , m = read () ;net.s = 0 , net.t = n - 1 , net.nv = net.t + 1 ;while ( m -- ) {u = read () , v = read () , c = read () , d = read () ;LL cc = c * 1000000LL + 1 ;if ( d )net.addedge ( u , v , cc , cc ) ;elsenet.addedge ( u , v , cc ) ;}LL flow = net.ISAP () ;printf ( "%I64d\n" , flow % 1000000 ) ;}int main () {int T , cas = 0 ;scanf ( "%d" , &T ) ;while ( T -- ) {printf ( "Case %d: " , ++ cas ) ;work () ;}return 0 ;}
0 0
- HDU 3987 Harry Potter and the Forbidden Forest 最小割
- 【HDU】3987 Harry Potter and the Forbidden Forest 最小割
- 【最小割】HDU 3987 Harry Potter and the Forbidden Forest
- hdu 3987 Harry Potter and the Forbidden Forest 最小割
- HDU 3987 Harry Potter and the Forbidden Forest(最小割中的最少割边)经典
- HDU--3987[Harry Potter and the Forbidden Forest] 求最小割集中的最小边数
- hdu 3987 Harry Potter and the Forbidden Forest 求割边最少的最小割
- HDU 3987 Harry Potter and the Forbidden Forest (求割边最少的最小割)
- hdu 3987 Harry Potter and the Forbidden Forest【网路流最小割模型】
- hdu 3987 Harry Potter and the Forbidden Forest (最小割)
- HDU 3987 Harry Potter and the Forbidden Forest(最小割的最少割边数)
- HDU3987 Harry Potter and the Forbidden Forest(最小割)
- hdu 3987 Harry Potter and the Forbidden Forest//边数最小的最小割 2种解题方法
- HDOJ 3987 - Harry Potter and the Forbidden Forest 设置偏移量,最小割
- Harry Potter and the Forbidden Forest(割边最小的最小割)
- hdu 3987 Harry Potter and the Forbidden Forest
- hdu 3987 Harry Potter and the Forbidden Forest
- HDU 3987 Harry Potter and the Forbidden Forest
- 手机照片丢失怎么恢复丨万能恢复软件免费版丨
- 让自己组织Sw所示把电参
- php面试经典问题
- matlab对数据分布检验代码:正态分布,γ分布,泊松分布,指数分布,rayleigh分布
- 环形buffer的实现
- 【HDU】3987 Harry Potter and the Forbidden Forest 最小割
- android x86 环境
- 程序员职业路径该如何抉择?Career Path of a Programmer
- 迭代器
- ORACLE备份保留策略(RETENTION POLICY)
- java位运算应用
- 电脑与CDI9600变频器的RS485通讯
- C# 中的委托和事件(详解,附实例)
- Codeforces Round #254 (Div. 2)