dfs一下
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
struct Edge {
Edge* next;
int end;
// EdgeData data;
};
struct Graph {
vector< Edge* > vs;
void init(int maxV) {
vs.resize(maxV);
int i;
for (i = 0; i < vs.size(); ++i) vs[i] = NULL;
}
Edge* newEdge() {
return new Edge;
}
void add(int start, int end) {
Edge* e = newEdge();
e->next = vs[start];
vs[start] = e;
e->end = end;
//e->data = data;
}
Edge* get(int index) {
return vs[index];
}
};
//============================================
vector< char > color;
vector< int > gAss;
vector< int > ansList;
int gMinAss;
int N;
Graph G;
int visitTree(int id) {
// printf("\nvisit %d\n", id);
color[id] = 'g';
Edge* curEdge;
int ass = -999999;
int son;
int sum = 0;
for (curEdge = G.get(id); curEdge; curEdge = curEdge->next) {
if (color[curEdge->end] == 'g') continue;
son = visitTree(curEdge->end);
sum = sum + son;
ass = max(ass, son);
}
if (id != 1)
ass = max(N - sum - 1, ass);
gAss[id] = ass;
gMinAss = min(ass, gMinAss);
color[id] = 'b';
return sum + 1;
}
void input() {
scanf("%d", &N);
int i;
int a, b;
G.init(N + 1);
for (i = 1; i <= N - 1; ++i) {
scanf("%d %d", &a, &b);
G.add(a, b);
G.add(b, a);
}
}
int main() {
int i;
input();
gMinAss = 99999999;
color.resize(N + 1);
gAss.resize(N + 1);
for (i = 0; i < color.size(); ++i) color[i] = 'w';
visitTree(1);
printf("%d", gMinAss);
ansList.clear();
for (i = 1; i <= N; ++i) {
if (gAss[i] == gMinAss)
ansList.push_back(i);
}
printf(" %d\n", ansList.size());
for (i = 0; i < ansList.size(); ++i) {
if (i != 0) printf(" ");
printf("%d", ansList[i]);
}
printf("\n");
}