Given a tree and Q paths, count how many paths use each edge and report the edge with the maximum count, breaking ties by lexicographic order of endpoints.
Medium7TreeDFSPrefix sumImplementationNo attempts yetTime limit2sMemory limit512 MBThe city state CINERIS has N railway stations. The N−1 tracks that join the stations form a tree, so exactly one route connects any two different stations.
Jeongmin, who governs the country, wants to know which segment the most people passed through. Q tickets have been sold so far, and a single ticket reveals only its departure station and its arrival station.
Every resident of CINERIS travels along a shortest route. In a tree the route between two stations is unique, so one ticket passes through each segment of that route exactly once. Use the Q tickets to find the segment that the most people passed through.
The first line contains N and Q.
Each of the next N−1 lines contains two integers a and b, meaning a two way track joins station a and station b.
Each of the following Q lines contains the departure station c and the arrival station d of one ticket. The person who bought that ticket left station c and arrived at station d.
1≤N≤222222, 1≤Q≤222222
The tracks form a tree, so every station is connected to every other one. An input with no track at all, that is N=1, is never given. The departure station and the arrival station of a ticket are different.
Print on one line the segment that the most people passed through and how many people passed through it. Print three integers a, b, c separated by spaces, meaning that c people passed through the segment joining station a and station b. Write the two station numbers in increasing order, so that a<b.
If several segments are tied for the most people, print the one whose pair (a,b) is smallest in lexicographic order. That is, take the segment with the smaller a, and among equal a take the one with the smaller b.