33OJ
登录 注册

#P14580. 【模板】有源汇上下界最小流

    ID: 16319 远端评测题 1000ms 512MiB 尝试: 1 已通过: 1 显示难度省选/NOI− 上传者: 标签>网络流上下界网络流模板题

【模板】有源汇上下界最小流

Problem Description

You are given a directed graph GG with nn vertices and mm directed edges. Each edge has a lower flow bound lil_i and an upper flow bound rir_i. There are also a source ss and a sink tt.

Find the minimum flow from the source ss to the sink tt, or report that no solution exists.

Input Format

The first line contains four positive integers n,m,s,tn,m,s,t, representing the number of vertices and the number of edges of the graph GG, as well as the index of the source and the index of the sink.

The following mm lines each contain four positive integers ui,vi,li,riu_i,v_i,l_i,r_i, representing the starting point and the ending point of each directed edge, as well as its lower flow bound and upper flow bound.

The graph may contain multiple edges and self-loops.

Output Format

Output the minimum flow from the source ss to the sink tt. If no solution exists, output N.

6 7 1 5
1 2 3 5
2 3 3 4
3 4 5 6
1 4 1 5
4 5 0 100000
6 3 0 1
4 6 1 2

5

6 6 4 1
4 1 0 5
4 2 0 6
4 3 0 7
2 2 3 3
5 6 1 1
6 5 2 2

N

Hint

Example 1 Explanation

Here vertex 11 is the source and vertex 55 is the sink.

Constraints

The graph may contain multiple edges and self-loops.

For all test data: 1≤n≤1031\leq n\leq 10^3, 1≤s,t≤n1\leq s,t\leq n, 1≤m≤1041\leq m\leq 10^4, 1≤ui,vi≤n1\leq u_i,v_i\leq n, 0≤li≤ri≤1050\leq l_i\leq r_i\leq 10^5.

It is guaranteed that s≠ts\neq t. For every ii, it is guaranteed that s≠vis\neq v_i and t≠uit\neq u_i.

Translated by QwenWork