#H2026H. Heal the Network

Heal the Network

Background

In year 3077 of the Stellar Calendar, the city Astra, floating above a sea of clouds, is kept running by a vast ether energy network.

The network consists of nn energy nodes and mm one-way energy transmission pipes. Energy starts from the main reactor ss and is ultimately delivered to the city core tt. Each pipe has its own capacity limit.

The central control system has already computed a set of maximum-energy transmission plans. To avoid energy circulating pointlessly in the network, all pipes carrying positive flow in this plan do not form a directed cycle.

However, an unexpected meteor shower damaged one of the pipes, reducing its capacity by exactly 11.

The city core may shut down at any moment due to insufficient energy. You need to compute a new maximum flow after the pipe is damaged as fast as possible.


Description

Given a directed graph G=(V,E),G=(V,E),

where:

  • V=n|V|=n, with nodes numbered 1,2,,n1,2,\ldots,n;
  • E=m|E|=m, with edges numbered 1,2,,m1,2,\ldots,m in input order;
  • ss is the source;
  • tt is the sink;
  • The ii-th edge goes from aia_i to bib_i and has positive integer capacity cic_i.

Also given is an integral flow ff, where the ii-th edge currently carries fif_i units of flow.

It is guaranteed that ff is a maximum ss-tt flow in the original graph; that is, it satisfies:

  1. 0fici0\le f_i\le c_i,

  2. For every v{s,t}v\notin \{s,t \}, we have

    $$\sum_{(u,v)\in E}f_{(u,v)}=\sum_{(v,w)\in E}f_{(v,w)}. $$

In addition, the given flow is acyclic. That is, after keeping only the edges with fi>0f_i>0, the resulting directed graph contains no directed cycle.

Now, the capacity of the pp-th edge is reduced by exactly 11. The modified capacities are

$$c'_i= \begin{cases} c_i-1,&i=p,\\ c_i,&i\ne p. \end{cases} $$

Output any integral maximum flow in the modified network.


Input Format

The first line contains five integers: n, m, s, t, pn,\ m,\ s,\ t,\ p, denoting the number of nodes, the number of edges, the source, the sink, and the index of the edge whose capacity is reduced, respectively.

The next mm lines each contain four integers: ai, bi, ci, fia_i,\ b_i,\ c_i,\ f_i, meaning that the ii-th edge goes from node aia_i to node bib_i, its original capacity is cic_i, and the original maximum flow sends fif_i units of flow along this edge.


Output Format

This problem uses a Special Judge.

The first line outputs an integer FF', the maximum flow value in the modified network.

The second line outputs mm integers f1,f2,,fmf'_1,f'_2,\ldots,f'_m, where fif'_i denotes the flow on the ii-th edge in the modified maximum flow.

The flow you output must satisfy:

  1. All fif'_i are integers;
  2. 0fici0\le f'_i\le c'_i for every edge;
  3. Flow conservation holds at every node except ss and tt;
  4. The value of this flow equals FF';
  5. FF' is the maximum flow value of the modified network.

If multiple valid answers exist, output any one of them.

The output new maximum flow is also required to be an acyclic flow.


Constraints

For all test data:

2n2×105,2\le n\le 2\times 10^5, 1m2×105,1\le m\le 2\times 10^5, 1s,tn,st,1\le s,t\le n,\qquad s\ne t, 1pm,1\le p\le m, 1ci109,1\le c_i\le 10^9, 0fici.0\le f_i\le c_i.

It is guaranteed that:

  • aibia_i\ne b_i;
  • The input graph may contain parallel edges;
  • The given flow ff is an integral maximum flow of the original graph;
  • The directed graph formed by all edges with fi>0f_i>0 contains no directed cycle;
  • The capacity of the pp-th edge may become 00 after the reduction;
  • The maximum flow value after the modification does not exceed 2×10142\times 10^{14}.

Sample Input

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

Sample Output

3
2 1 1 1 2 3

Explanation

The value of the original maximum flow is 33.

The 44-th edge is

24,2\rightarrow 4,

and its capacity was reduced from 22 to 11. Therefore, of the two units of flow originally passing through this edge, one unit can no longer be delivered along the original route.

This one unit of flow can be rerouted as

234.2\rightarrow 3\rightarrow 4.

The adjusted edge flows are:

Edge ID Pipe New Capacity New Flow
11 121\rightarrow2 22 22
22 131\rightarrow3 11
33 232\rightarrow3 11
44 242\rightarrow4
55 343\rightarrow4 22
66 454\rightarrow5 33

Thus, even with one pipe damaged, the network can still maintain a maximum flow with value 33.