bzoj#P1447. Moving the Hay

Moving the Hay

题目描述

After he partitioned his farm into rr rows and cc squares conveniently labeled (1,1)(1,1) through (r,c)(r,c), Farmer John spent days cutting the hay and stacking a huge amount of it in square (1,1)(1,1). He then undertook the task of mapping out the nn haypaths through the farm so that he could deduce the maximum rate he could move hay from square (1,1)(1,1) to square (r,c)(r,c). Each haypath uniquely connects the middle of two rectilinearly adjacent partitioned squares and has some capacity limit lil_i that is the maximum amount of hay that can be transported in either direction across the haypath. He's just positive that he can move hay at a reasonable rate to the other side of the farm but he doesn't know what the fastest rate is. Help him learn it.

输入格式

Line 11: Three separated integers: r,cr,c, and nn

Lines 2n+12\cdots n+1: Line i+1i+1 describes path ii with five space-separated integers: r1,c1,r2,c2,lir_1,c_1,r_2,c_2,l_i which denote a haypath connecting (r1,c1)(r1,c1) to (r2,c2)(r2,c2) with capacity lil_i.

输出格式

Line 11: One number, on a line by itself, the maximum amount of material which can be transported from (1,1)(1,1) to (r,c)(r,c) simultaneously.

3 3 8
1 1 1 2 5
1 1 2 1 3
1 2 2 2 5
2 1 2 2 2
2 2 2 3 1
2 2 3 2 6
2 3 3 3 4
3 2 3 3 7
7

样例解释

The grid is as follows:

*--5--* . . *
|     |     
3     5     :
|     |    
*--2--*--1--*
      |     |
:     6     4
      |     |
* . . *--7--*

数据规模与约定

对于 100%100\% 的数据,1r,c2001\leq r,c\leq 2001n8×1041\leq n\leq 8\times 10^41li2×1071\leq l_i\leq 2\times 10^7