#P3128. Overloaded Stalls
Overloaded Stalls
Overloaded Stalls
Farmer John has installed a system of \(N-1\) pipes to transport milk between the \(N\) stalls in his barn, numbered \(1,\ldots,N\). Each pipe connects two stalls, and all stalls are connected by a unique path. Milk is being pumped along \(K\) pairs of stalls. For the \(i\)th pair, you are given two stalls \(s_i\) and \(t_i\). Milk flows through every stall on the unique path between \(s_i\) and \(t_i\) (including the endpoints).
The task is to determine the maximum amount of milk that flows through any single stall when milk is pumped simultaneously along all \(K\) paths.
Input Format
The first line contains two integers \(N\) and \(K\) ( \(2 \le N \le 50{,}000\) and \(1 \le K \le 100{,}000\)).
The next \(N-1\) lines each contain two integers \(u\) and \(v\), indicating a bidirectional pipe connecting stalls \(u\) and \(v\).
The following \(K\) lines each contain two integers \(s_i\) and \(t_i\), representing the endpoints of a milk pumping path.
Output Format
Output a single integer: the maximum number of milk flows through any stall.
inputFormat
The input begins with two integers \(N\) and \(K\). Following that are \(N-1\) lines, each containing two integers denoting a pipe between two stalls. Then, there are \(K\) lines, each with two integers \(s_i\) and \(t_i\), indicating the milk pumping paths.
outputFormat
Output a single integer which is the maximum milk flow passing through any stall.
sample
4 3
1 2
2 3
3 4
1 3
2 4
1 4
3
</p>