Arbitrary circulation#4590

Arbitrary circulation

1 second
64 megabytes
Hard

Given a directed network , each edge is assigned a capacity c_i and a lower bound l_i on the flow through it. For each edge, the flow f_i must satisfy l_i \le f_i \le c_i.

A circulation in the network is a flow such that, for every vertex, the total flow into the vertex equals the total flow out of it. That is, for every vertex, the sum of incoming flows equals the sum of outgoing flows. (In typical flow problems, this condition is not required for the source and sink, but in circulation, it applies to all vertices.)

Your task is to find any circulation in the given network.

Input

The first line contains two integers and (1 \le n \le 200, 0 \le m \le 400) — the number of vertices and edges in the network, respectively. Each of the next lines describes an edge in the format \text{from}_i\ \text{to}_i\ l_i\ c_i, where \text{from}_i is the starting vertex, \text{to}_i is the ending vertex, l_i is the lower bound on the flow, and c_i is the capacity (1 \le \text{from}_i,\ \text{to}_i \le n, 0 \le l_i \le c_i \le 10^5). All numbers are integers. The graph contains no multiple edges or loops.

If an edge from to exists, then there is no edge from to (i.e., no pair of reverse edges is present).

Output

If no circulation exists, print NO. Otherwise, print YES and then lines: the -th of them should contain the flow f_i through the -th edge in the found circulation.

Examples

Example 1

Loading
Loading