Count how many of the K given tree paths pass through each stall and report the largest count.
Medium6TreePrefix sumDFSNo attempts yetTime limit2sMemory limit512 MBFarmer John has installed a new system of N−1 pipes to transport milk between the N stalls in his barn (2≤N≤50,000), numbered 1 through N. 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 K pairs of stalls (1≤K≤100,000). The ith pair is given as two stalls si and ti, 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 si to ti counts as pumped through the endpoint stalls si and ti, and through every stall on the path between them.
The first line contains N and K.
Each of the next N−1 lines contains two integers x and y (x=y), describing a pipe between stalls x and y.
Each of the next K lines contains two integers s and t, the endpoint stalls of a path through which milk is pumped. Here 1≤s,t≤N, and s may equal t, in which case the milk passes through that one stall only.
Print one integer, the maximum amount of milk pumped through any stall in the barn.