This page is still under construction.

Parts of this page are still being built. What you see may change.

Traffic (Small)

Interview

Time limit2sMemory limit512 MB

Summary
Given a tree and Q tickets, count how many tickets use each edge along the unique path, then report the edge with the largest count (smallest station pair on ties).
Level

Medium5 of 10

Topics
Tree, Prefix sum, Linked list, DFS
Solved
No attempts yet

Problem

The city state CINERIS has N train stations, and the rails that connect them form a tree, so exactly one route runs between any two different stations. Jeongmin, who rules the country, wants to know which rail carried the most people. Q tickets have been sold so far, and a ticket records only its departure station and its arrival station.

Everyone in CINERIS travels along the shortest route. A tree holds exactly one route between two stations, so one ticket passes each rail on the route from its departure station to its arrival station exactly once. A ticket whose departure and arrival stations are the same passes no rail. From the Q tickets, find the rail that carried the most people.

Input

The first line contains N and Q separated by a space.

Each of the next N - 1 lines contains two integers a and b, meaning a two way rail connects station a and station b.

Each of the next Q lines contains the departure station c and the arrival station d of one ticket, meaning the buyer left station c and arrived at station d.

2≤N≤22222 \le N \le 2222, 1≤Q≤2222221 \le Q \le 222222, 1≤a,b,c,d≤N1 \le a, b, c, d \le N, and the rails always form a tree.

Output

Print the rail that carried the most people and how many people passed it, as a b c on one line. It means c people passed the rail connecting station a and station b. Write the two station numbers in increasing order so that a<ba < b. If several rails carry the maximum, print the one whose pair (a, b) is smallest in lexicographic order.

Examples4

  1. Example 1

    Input
    4 7
    1 2
    2 3
    3 4
    1 3
    2 4
    1 2
    3 4
    1 4
    2 3
    1 3
    
    Expected output
    2 3 5
    
  2. Example 2

    Input
    2 1
    1 2
    1 2
    
    Expected output
    1 2 1
    
  3. Example 3

    Input
    4 3
    1 2
    1 3
    1 4
    2 3
    3 4
    2 4
    
    Expected output
    1 2 2
    
  4. Example 4

    Input
    6 8
    1 2
    2 3
    3 4
    4 5
    5 6
    1 6
    2 5
    3 3
    6 1
    4 6
    1 3
    5 2
    2 4
    
    Expected output
    2 3 6