eolymp
bolt
Try our new interface for solving problems
Problems

Three Cities

Three Cities

In one state there are \textbf{N} cities. Some cities are connected by roads, and for any two cities \textbf{A} and \textbf{B} the following property: there is exactly one way to get from city \textbf{A} to city \textbf{B} if you can only move along roads and are not allowed to pass through the same road more than once. Recently, the president of this country interested in the question: what are the three cities are the most distant from each other. Namely, we call the mutual distance from each other in three cities \textbf{A}, \textbf{B} and \textbf{C}, the minimum number of roads that should be used to get from \textbf{A} to \textbf{B}, then from \textbf{B} to \textbf{C} and then from \textbf{C} to \textbf{A} (in this case is allowed to use one and the the same way in different journeys). Required to find the three cities for which the mutual distance from each other will be maximum. For example, for the five cities connected by roads, as shown in Figure 1, the three most distant of the town is \textbf{1}, \textbf{2} and \textbf{5} (the mutual distance is \textbf{2 + 3 + 3 = 8}), and for the cities in Figure 2 - it's all three cities, chosen from the set \textbf{\{1, 2, 4, 5\}} (distance \textbf{2 + 2 + 2 = 6}). \InputFile The first line contains the number \textbf{N} - the number of cities (\textbf{3} ≤ \textbf{N} ≤ \textbf{1000}). The next \textbf{N} lines contain a description of the cities. Description of \textbf{i}-City first contains \textbf{K_i} - the number of cities with which it is connected to roads(\textbf{1} ≤ \textbf{K_i} < \textbf{N}), then \textbf{K_i} numbers - the number of cities with which it is connected. It is guaranteed that the input data is valid is if there is a road from city \textbf{A} to city \textbf{B}, then there is a way out of city \textbf{B} to city \textbf{A}, and for all pairs of cities holds the property specified in the problem. \OutputFile Output three different numbers - numbers of the three most distant cities in random order. If several solutions, output any of them.
Time limit 1 second
Memory limit 64 MiB
Input example #1
5
1 3
1 3
3 1 2 4
2 3 5
1 4
Output example #1
5 2 1