Mobile Network Bandwidth
Time limit8sMemory limit512 MB
Given a graph whose edge capacities are polynomials in x, output the max-flow polynomial from node 1 to node N for large x.
- Level
Hard9 of 10
- Topics
- Graph, Greedy, Math, Implementation
- Solved
- No attempts yet
Problem
Internet traffic keeps growing because of smartphones, so wireless carriers have to expand their networks.
The network of a carrier consists of base stations and lines. Each line connects two base stations in both directions. The bandwidth of a line grows every year and is given as a polynomial of the year .
Given the structure of the network, compute the maximum bandwidth between base station 1 and base station as a polynomial of .
The traffic between the two stations can be split over several routes. The traffic on a line cannot exceed the bandwidth of that line, so the maximum bandwidth equals the maximum flow from station 1 to station .
Which line is the bottleneck depends on . Exactly one polynomial equals the maximum bandwidth for every sufficiently large . Print that polynomial.
Input
The input consists of several datasets. Each dataset has the following format.
N M
u1 v1 p1
...
uM vM pM
The first line contains the number of base stations () and the number of lines (). The next lines describe the network. The -th of them contains the station indices and () and the polynomial that gives the bandwidth of the line. Several lines may connect the same pair of stations, and a line may have both of its ends at the same station.
A polynomial has the form
where () is the degree and (, ) are the coefficients. The input writes a polynomial by these rules.
- A term with is written as
<a_i>x^<i>. - The linear term is written as
<a_1>x. - The constant term is written as digits only.
- The terms are written in strictly decreasing order of degree and joined by
+. - For a term other than the constant one, the coefficient is omitted when .
- A term with is omitted entirely.
- A polynomial contains no space and no character other than digits,
x,^, and+.
So is written as 2x^2+3x+5, and is written as 2x^3+x, never as 2x^3+0x^2+1x+0. No polynomial in the input has all coefficients equal to .
The end of the input is a line with two zeros. That line is not a dataset.
Output
For each dataset, print the maximum bandwidth as a polynomial of on one line. Use the same notation as the input, except that the answer may be the constant , which is printed as 0.