Under construction

Still being built. Things may change

Berland Football Union

Interview

Time limit2sMemory limit1024 MB

Summary
Given a weighted tree, find every vertex where the sum of squared distances to all other vertices is minimal.
Level

Medium6 of 10

Topics
Tree, Dynamic programming, DFS
Solved
No attempts yet

Statement

The third division of the Berland football championship has nn teams from nn different cities. Teams travel only along special roads built by the Berland Football Union. Each road connects two different cities and can be used in both directions. Each road has a length in kilometers.

Any two cities are connected by exactly one path made of special roads that visits each city at most once. Officials and experts also travel only along these roads.

The union wants to build its headquarters in one of these nn cities. Each month, nn experts leave the headquarters, one for each city, to check the quality of fields and stadiums. An expert who travels to a city dd kilometers from the headquarters receives a bonus of d2d^2 Berland rubles.

The union head is very thrifty. He wants the headquarters in a city where the total bonus paid to the experts is minimal. Output the list of candidate cities where the headquarters can be built.

Input

The first line contains an integer nn (1≤n≤1051 \le n \le 10^5), the number of cities. Each of the next n−1n-1 lines contains three integers uu, vv, and ww (1≤u,v≤n1 \le u, v \le n, 1≤w≤1001 \le w \le 100, u≠vu \neq v): cities uu and vv are connected by a road of length ww kilometers.

Output

Print the number kk of candidate cities that satisfy the condition on the first line. On the second line, print the kk city numbers separated by spaces, in any order.

Examples1

  1. Example 1

    Input
    6
    6 3 35
    5 2 12
    4 5 31
    4 6 14
    3 1 40
    
    Expected output
    1
    6