Each directed road carries at most one truck; find whether reversing one road increases the max number of edge-disjoint S-to-T paths, the new maximum, and how many roads achieve it.
Hard9GraphBFSShortest pathImplementationNo attempts yetTime limit8sMemory limit512 MBJAG Kingdom has N cities, numbered 1 through N, and every road between them is one way. ICPC (International Characteristic Product Corporation) ships products every day from its factory in city S to its storehouse in city T. Several trucks run at the same time. Each truck starts at S, follows one way roads, and reaches T, passing through other cities on the way or going there directly. To reduce the risk of traffic jams and accidents, no two trucks use the same road.
ICPC already runs as many trucks as that rule allows, and it wants the daily transport to be more efficient. JAG Kingdom, whose finances depend heavily on ICPC, is considering a change of direction of one one way road so that more trucks can run. Reversing many roads causes confusion, so the kingdom reverses at most one road.
If no single reversal raises the number of trucks, the kingdom leaves every road as it is. Decide whether reversing one road raises the current maximum number of trucks. If it does, compute the maximum number of trucks that take pairwise disjoint sets of roads when one road may be reversed, and the number of roads that can be chosen as the road to reverse to reach that maximum.
The input holds several datasets. The number of datasets is at most 100.
Each dataset has the following format.
N M S T
a1 b1
a2 b2
:
:
aM bM
The first line of a dataset holds four integers: the number of cities N (2≤N≤1000), the number of roads M (1≤M≤10000), the city with the factory S, and the city with the storehouse T (1≤S,T≤N, S=T).
The next M lines describe the roads. The i-th of those lines holds two integers ai and bi (1≤ai,bi≤N, ai=bi), meaning that road i is directed from ai to bi. Several roads may connect the same pair of cities, and each road counts separately.
The end of the input is a line holding four zeros.
For each dataset, print two integers separated by one space on a single line. If reversing one road raises the current maximum number of trucks, the first integer is the new maximum after the reversal and the second integer is the number of roads that can be chosen as the road to reverse to reach that new maximum. Otherwise, the first integer is the current maximum and the second integer is 0.