Max Flow
Time limit2sMemory limit512 MB
Count how many of the K given tree paths pass through each stall and report the largest count.
- Level
Medium6 of 10
- Topics
- Tree, Prefix sum, DFS
- Solved
- No attempts yet
Problem
Farmer John has installed a new system of pipes to transport milk between the stalls in his barn (), numbered through . Each pipe connects a pair of stalls, and every stall is reachable from every other stall along pipes. The barn is a tree, so the path between two stalls is unique.
Farmer John is pumping milk between pairs of stalls (). The th pair is given as two stalls and , the endpoints of a path along which milk is pumped at a unit rate. A stall can be a waypoint on many of those paths, so Farmer John worries that some stall ends up overwhelmed. Determine the maximum amount of milk pumped through any stall. Milk pumped from to counts as pumped through the endpoint stalls and , and through every stall on the path between them.
Input
The first line contains and .
Each of the next lines contains two integers and (), describing a pipe between stalls and .
Each of the next lines contains two integers and , the endpoint stalls of a path through which milk is pumped. Here , and may equal , in which case the milk passes through that one stall only.
Output
Print one integer, the maximum amount of milk pumped through any stall in the barn.