#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> E; vector dp, res; Reroot() { } Reroot(int n) { N = n; E.clear(); E.resize(0); E.resize(n); } void add(int a, int b) { E[a].push_back(b); E[b].push_back(a); } vector build() { dp.resize(N); res.resize(N); dfs1(0); dfs2(0); return res; } void dfs1(int cu, int pa = -1) { dp[cu] = def; fore(to, E[cu]) if (to != pa) { dfs1(to, cu); dp[cu] = comp(dp[cu], dp[to]); } } void dfs2(int cu, int pa = -1) { res[cu] = def; fore(to, E[cu]) res[cu] = comp(res[cu], dp[to]); int cnt = 0; fore(to, E[cu]) if (dp[to]) cnt++; T bak = dp[cu]; fore(to, E[cu]) if (to != pa) { if (dp[to]) cnt--; if (cnt == 0) dp[cu] = true; else dp[cu] = false; dfs2(to, cu); if (dp[to]) cnt++; } dp[cu] = bak; /*int n = E[cu].size(); vector lft(n), rht(n); lft[0] = dp[E[cu][0]]; rep(i, 1, n) lft[i] = comp(lft[i - 1], dp[E[cu][i]]); rht[n-1] = dp[E[cu][n-1]]; rrep(i, n-2, 0) rht[i] = comp(rht[i + 1], dp[E[cu][i]]); T bak = dp[cu]; rep(i, 0, n) if (E[cu][i] != pa) { if (n == 1) dp[cu] = def; else if (i == 0) dp[cu] = rht[1]; else if (i == n - 1) dp[cu] = lft[n - 2]; else dp[cu] = comp(lft[i - 1], rht[i + 1]); dfs2(E[cu][i], cu); } dp[cu] = bak;*/ } }; template struct BIT { BIT() {} // [L, R) int NV;vector bit; BIT(int n){ init(n); } void init(int n) { NV = 1; while (NV < n)NV *= 2; bit.resize(NV); clear(); } V operator[](int e) { V s = 0; e++; while (e) s += bit[e - 1], e -= e&-e; return s; } void add(int e, V v) { e++; while (e <= NV) bit[e - 1] += v, e += e&-e; } int lower_bound(V val) { V tv = 0; int i, ent = 0; for (i = NV - 1; i >= 0; i--) if(tv+bit[ent+(1< &dist) { rep(i, 0, N) { ll d = -1; if (td.dia % 2 == 0) { chmax(d, (ll)hld.distance(i, td.leaf_even[0])); chmax(d, (ll)hld.distance(i, td.leaf_even[1])); } else { chmax(d, (ll)hld.distance(i, td.leaf_odd.first[0])); chmax(d, (ll)hld.distance(i, td.leaf_odd.second[0])); } dist[i] = d; } }*/ //--------------------------------------------------------------------------------------------------- void _main() { /*int N, M; cin >> N; TreeDiameter td1; td1.init(N); HLDecomposition hld1; hld1.init(N); rep(i, 0, N - 1) { int a, b; cin >> a >> b; a--; b--; td1.add_edge(a, b); hld1.add(a, b); } td1.build(); hld1.build(); cin >> M; TreeDiameter td2; td2.init(M); HLDecomposition hld2; hld2.init(M); rep(i, 0, M - 1) { int a, b; cin >> a >> b; a--; b--; td2.add_edge(a, b); hld2.add(a, b); } td2.build(); hld2.build(); ll ma = -1; chmax(ma, 1LL * td1.dia); chmax(ma, 1LL * td2.dia); vector dist1(N), dist2(M); solve(td1, hld1, N, dist1); solve(td2, hld2, M, dist2); BIT bit1(101010), bit2(101010); rep(i, 0, N) bit1.add(dist1[i], 1); rep(i, 0, M) bit2.add(dist2[i], 1); ll other = 0; ll ans = 0; rep(i, 0, N) { ll ng = 0; if(0 <= ma - dist1[i]) ng = bit2.get(0, ma - dist1[i]); other += ng; ans += dist1[i] * (M - ng); } rep(i, 0, M) { ll ng = 0; if (0 <= ma - dist2[i]) ng = bit1.get(0, ma - dist2[i]); other += ng; ans += dist2[i] * (N - ng); } ans += ma * other / 2; ans += 1LL * (1LL * N * M - other / 2); cout << ans << endl;*/ int N; cin >> N; Reroot rr(N); rep(i, 0, N - 1) { int a, b; cin >> a >> b; a--; b--; rr.add(a, b); } auto dp = rr.build(); vector ans; rep(i, 0, N) if (dp[i]) ans.push_back(i); int n = ans.size(); printf("%d\n", n); fore(i, ans) printf("%d\n", i + 1); }