Cost Performance Flow

Find an s-t flow minimizing squared cost plus squared shortfall from max flow in a capacitated graph with edge costs, and print the minimum as a fraction.

Hard8GraphShortest pathMathNo attempts yetTime limit2sMemory limit256 MB

Problem

Yayoi is an expert at saving money. She never picks an item just because it is cheap, and her motto is "cost performance". That is one reason she cooks so well with bean sprouts. Word of her thrift has spread, so people keep asking her to cut costs of all kinds. This time the job is optimizing a network flow.

Consider a directed graph G=(V,E)G = (V, E), where V={1,2,,V}V = \{1, 2, \dots, |V|\} is the vertex set and EV×VE \subset V \times V is the edge set. Every edge ee has a capacity u(e)u(e) and a cost c(e)c(e). For two vertices ss and tt, a function fs,t:ERf_{s,t} : E \to \mathbb{R} is an ss-tt flow when both of the following hold.

  • 0fs,t(e)u(e)0 \le f_{s,t}(e) \le u(e) for every edge eEe \in E.
  • For every vertex vV{s,t}v \in V \setminus \{s, t\}, the flow entering vv equals the flow leaving vv, that is e=(w,v)Efs,t(e)=e=(v,w)Efs,t(e)\sum_{e = (w, v) \in E} f_{s,t}(e) = \sum_{e = (v, w) \in E} f_{s,t}(e).

The value and the cost of fs,tf_{s,t} are defined as follows.

F(fs,t)=e=(s,v)Efs,t(e)e=(v,s)Efs,t(e),C(fs,t)=eEfs,t(e)c(e)F(f_{s,t}) = \sum_{e = (s, v) \in E} f_{s,t}(e) - \sum_{e = (v, s) \in E} f_{s,t}(e), \qquad C(f_{s,t}) = \sum_{e \in E} f_{s,t}(e) c(e)

Optimizing a network flow usually means minimizing the cost among the maximum flows. Yayoi judges by cost performance instead. Let Fmax=maxfF(f)F_{\max} = \max_f F(f) be the maximum value over all ss-tt flows ff, and define the balance function of an ss-tt flow fs,tf_{s,t} as follows.

B(fs,t)=C(fs,t)2+(FmaxF(fs,t))2B(f_{s,t}) = C(f_{s,t})^2 + (F_{\max} - F(f_{s,t}))^2

Yayoi regards the flow that minimizes BB as the one with the best cost performance. Compute the minimum of B(fs,t)B(f_{s,t}) over all ss-tt flows.

Input

The input is a single test case. The first line has two integers separated by one space: the number of vertices NN (2N1002 \le N \le 100) and the number of edges MM (1M10001 \le M \le 1\,000). The second line has two vertices ss and tt (1s,tN1 \le s, t \le N, sts \ne t). Each of the following MM lines describes one edge with four integers aia_i, bib_i, uiu_i, cic_i. The ii-th edge goes from aia_i to bib_i (1ai,biN1 \le a_i, b_i \le N), its capacity is uiu_i (1ui1001 \le u_i \le 100), and its cost is cic_i (1ci1001 \le c_i \le 100). For every ii, aibia_i \ne b_i, and (ai,bi)(aj,bj)(a_i, b_i) \ne (a_j, b_j) whenever iji \ne j.

Output

Print the minimum of BB on one line as an irreducible fraction. Precisely, print "u/d", where uu is the numerator and dd is the denominator. Both uu and dd must be non-negative integers whose greatest common divisor is 1. The answer is always a rational number. If the minimum is 0, print "0/1".