p134.ans1
======================
3 1
1

=================
p134.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n;
vector<vector<int>> adj;
vector<int> tr_sz;

void read() {
    cin >> n;
    adj.assign(n + 1, {});
    for(int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}

void dfs(int u, int pr) {
    tr_sz[u] = 1;
    for(int v: adj[u]) {
        if(v != pr) {
            dfs(v, u);
            tr_sz[u] += tr_sz[v];
        }
    }
}

void solve() {
    /*
     * Centroid by subtree sizes. Root the tree at vertex 1 and compute tr_sz
     * via DFS. Removing vertex u leaves components: the "up" part of size
     * n - tr_sz[u], and one component per child v of size tr_sz[v]. The value
     * val[u] is the largest such component, i.e. max(n - tr_sz[u], max child
     * subtree). A neighbour v is a child iff tr_sz[v] < tr_sz[u] (its size is
     * smaller under this rooting). The centroids are all vertices attaining the
     * minimum val, listed in ascending order.
     */

    tr_sz.assign(n + 1, 0);
    dfs(1, 1);

    vector<int> val(n + 1, 0);
    int mn = n;
    for(int u = 1; u <= n; u++) {
        val[u] = n - tr_sz[u];
        for(int v: adj[u]) {
            if(tr_sz[v] < tr_sz[u]) {
                val[u] = max(val[u], tr_sz[v]);
            }
        }

        mn = min(mn, val[u]);
    }

    vector<int> li;
    for(int i = 1; i <= n; i++) {
        if(val[i] == mn) {
            li.push_back(i);
        }
    }

    cout << mn << " " << li.size() << '\n';
    for(int x: li) {
        cout << x << " ";
    }
    cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}

=================
p134.in1
======================
7
1 2
2 3
2 4
1 5
5 6
6 7

=================
statement.txt
======================
134. Centroid

time limit per test: 0.25 sec.
memory limit per test: 4096 KB


You are given an undirected connected graph, with N vertices and N-1 edges (a tree). You must find the centroid(s) of the tree.
In order to define the centroid, some integer value will be assosciated to every vertex. Let's consider the vertex k. If we remove the vertex k from the tree (along with its adjacent edges), the remaining graph will have only N-1 vertices and may be composed of more than one connected components. Each of these components is (obviously) a tree. The value associated to vertex k is the largest number of vertices contained by some connected component in the remaining graph, after the removal of vertex k. All the vertices for which the associated value is minimum are considered centroids.


Input

The first line of the input contains the integer number N (1<=N<=16 000). The next N-1 lines will contain two integers, a and b, separated by blanks, meaning that there exists an edge between vertex a and vertex b.


Output

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.


Sample Input

7
1 2
2 3
2 4
1 5
5 6
6 7
Sample Output

3 1
1
Author	: Mugurel Ionut Andreica
Resource	: SSU::Online Contester Fall Contest #2
Date	: Fall 2002

=================
