// clang-format off #include #include #include #define mp make_pair #define fst first #define snd second #define forn(i,n) for (int i = 0; i < int(n); i++) #define forn1(i,n) for (int i = 1; i <= int(n); i++) #define popcnt __builtin_popcountll #define ffs __builtin_ffsll #define ctz __builtin_ctzll #define clz __builtin_clz #define clzll __builtin_clzll #define all(a) (a).begin(), (a).end() using namespace std; using namespace __gnu_pbds; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair; using pli = pair; using pil = pair; using pll = pair; template using vec = vector; using vi = vec; using vl = vec; template using que = queue; template using deq = deque; template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; template using ordered_map = tree, rb_tree_tag, tree_order_statistics_node_update>; template T id(T b) {return b;}; template void chmax(T &x, T y) {if (x < y) x = y;} template void chmin(T &x, T y) {if (x > y) x = y;} template bool contains(S &s, K k) { return s.find(k) != s.end(); } template bool getf(T flag, size_t i) { return (flag>>i) & 1; } template T setf(T flag, size_t i) { return flag | (T(1)< T unsetf(T flag, size_t i) { return flag & ~(T(1)< class Rerooting { int n; vector>> g; vector ans; vector> dp; S dfs1(int u, int p) { M s = em(); int k = g[u].size(); dp[u] = vector(k); for (int i = 0; i < k; i++) { auto [v, c] = g[u][i]; if (v == p) continue; dp[u][i] = dfs1(v, u); s = introduce(s, dp[u][i], c, u, v); } return subtree(s, u); } void dfs2(int u, S par, int p) { int k = g[u].size(); for (int i = 0; i < k; i++) { auto [v, c] = g[u][i]; if (v == p) { dp[u][i] = par; } } vector dp_l(k + 1, em()), dp_r(k + 1, em()); for (int i = 0; i < k; i++) { dp_l[i + 1] = introduce(dp_l[i], dp[u][i], g[u][i].second, u, g[u][i].first); } ans[u] = result(dp_l[k], u); for (int i = k - 1; i >= 0; i--) { dp_r[i] = introduce(dp_r[i + 1], dp[u][i], g[u][i].second, u, g[u][i].first); } for (int i = 0; i < k; i++) { auto [v, c] = g[u][i]; if (v == p) continue; dfs2(v, subtree(merge(dp_l[i], dp_r[i + 1], u), u), u); } } public: Rerooting(int n) : n(n), g(n), ans(n) { } void add_edge(int u, int v, C c = {}) { assert(0 <= u && u < n); assert(0 <= v && v < n); g[u].emplace_back(v, c); g[v].emplace_back(u, c); } vector calc() { dp = vector>(n); dfs1(0, -1); dfs2(0, {}, -1); return ans; } }; } using S = bool; using M = bool; using C = bool; using R = S; M merge(M a, M b, int) { return a and b; } M introduce(M a, S b, C c, int, int) { return a and !b; } M em() { return true; } R result(M a, int) { return a; } using rerooting = aclext::Rerooting; int main() { fastio(); int n; cin >> n; rerooting r(n); forn(i, n - 1) { int u, v; cin >> u >> v; u--, v--; r.add_edge(u, v); } auto ans = r.calc(); cout << count(all(ans), true) << "\n"; forn(i, n) { if (ans[i]) { cout << (i + 1) << "\n"; } } return 0; }