33OJ
登录 注册

#P14578. 【模板】无源汇上下界可行流

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

【模板】无源汇上下界可行流

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.

You need to determine whether there exists a plan such that the flow wiw_i of every edge satisfies the flow restriction li≤wi≤ril_i\leq w_i\leq r_i, and the flow is balanced at every vertex, that is, the incoming flow equals the outgoing flow at every vertex.

Construct a set of flows satisfying the above restrictions, or report that no solution exists.

Input Format

The first line contains two positive integers n,mn,m, representing the number of vertices and the number of edges of the graph GG.

The following mm lines each contain four non-negative 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

If a feasible plan exists, output Yes on the first line, and then mm lines each containing one non-negative integer wiw_i, representing the actual flow of the ii-th edge.

If no feasible plan exists, output No.

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

Yes
4
4
5
4
0
1
1

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

No

Hint

Example 1 Explanation

The figure shows the flow plan given in the sample output.

Constraints

The graph may contain multiple edges and self-loops.

For all test data: 1≤n≤1031\leq n\leq 10^3, 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.

Translated by QwenWork