Banner Home Page Web Contests Problems Ranklist Status Statistics

Centroid

Time Limit : 1000/500ms (Java/Other)   Memory Limit : 8192/4096K (Java/Other)
Total Submission(s) : 6   Accepted Submission(s) : 2
Problem Description


You are given an undirected
connected graph, with <b>N</b> vertices and <b>N-1</b> edges (a tree).
You must find the centroid(s) of the tree.
<br>In order to define
the centroid, some integer value will be assosciated to every vertex. Let's
consider the vertex <b>k</b>. If we remove the vertex <b>k</b> from the
tree (along with its adjacent edges), the remaining graph will have only
<b>N-1</b>
vertices and may be composed of more than one connected components. Each
of these components is (obviously) a tree. The value associated to vertex
<b>k</b>
is the largest number of vertices contained by some connected component
in the remaining graph, after the removal of vertex <b>k</b>. All the vertices
for which the associated value is minimum are considered centroids.
</P>
<p></P>
<B><p>Input</P></B>
<p>
The first line of
the input contains the integer number <b>N</b> (<b>1&lt;=N&lt;=16 000</b>).
The next <b>N-1</b> lines will contain two integers, <b>a</b> and <b>b</b>,
separated by blanks, meaning that there exists an edge between vertex <b>a</b>
and vertex <b>b</b>.
</P>
<p></P>
<B><p>Output</P></B>
<p>
You should print two
lines. The first line should contain the minimum value associated to the
centroid(s) and the number of centroids. The second line should contain
the list of vertices which are centroids, sorted in ascending order.
</P>
<p></P>
<p>Sample Input</P>
<FONT FACE="Courier New">
<p>
7
1 2
2 3
2 4
1 5
5 6
6 7
</PRE>
<p></P>
</FONT>


<p>Sample Output</P>
<FONT FACE="Courier New">
<p>
3 1
1
</PRE>
</FONT>
</td></tr>
<tr><td>
 

Statistic | Submit | Back