Yonsei Mask Factory
Time limit1sMemory limit1024 MB
Assign each one-way passage a flow between its minimum s_i and maximum e_i so every site's net flow matches p_i, or report that it is impossible.
Problem
Yonsei University built a mask factory to prepare for COVID-19.
The factory has production sites and one-way passages connecting them. There is also an underground space that sends masks to each site or receives masks from it. No two distinct sites are connected by more than one passage, and no site is connected to itself.
Each site has an integer . If is positive, the site receives masks per second from the underground space. If is negative, the site sends masks per second to the underground space. Each passage is given a minimum number of masks and a maximum number of masks that may be sent per second.
The production sites and the underground space must keep the number of masks they hold unchanged every second.
Find how many masks each passage must carry per second under these conditions.
Input
The input is given as follows.
N M
p_1 ... p_N
u_1 v_1 s_1 e_1
...
u_M v_M s_M e_M
Output
On the first line, print 1 if a valid answer exists and -1 if it does not.
If a valid answer exists, print lines. The -th line contains the number of masks passage carries per second. If several answers exist, print any one of them.
Constraints
- .
- , ()
- ()