#include #include #include #define show(x) std::cerr << #x << " = " << (x) << std::endl template std::ostream& operator<<(std::ostream& os, const std::vector& v) { os << "["; for (const auto& p : v) { os << p << ","; } return (os << "]\n"); } int main() { int N; std::cin >> N; std::vector> g(N); for (int i = 0, a, b; i < N - 1; i++) { std::cin >> a >> b, a--, b--, g[a].push_back(b), g[b].push_back(a); } std::vector win(N); std::vector one(N, 0); // 子供に勝木が何個あるか auto dp = [&](auto&& self, const int s, const int p) -> bool { for (const int to : g[s]) { if (to == p) { continue; } one[s] += self(self, to, s); } return win[s] = one[s] == 0; }; dp(dp, 0, -1); show(one), show(win); std::vector ans; auto dp2 = [&](auto&& self, const int s, const int p) -> void { if (p == -1) { if (win[s]) { ans.push_back(s); } } else { const int pone = one[p] - win[s]; win[p] = pone == 0, one[s] += win[p]; if (one[s] == 0) { ans.push_back(s); } } for (const int to : g[s]) { if (to == p) { continue; } self(self, to, s); } }; dp2(dp2, 0, -1); std::cout << ans.size() << std::endl; std::sort(ans.begin(), ans.end()); for (const int e : ans) { std::cout << e + 1 << std::endl; } return 0; }