#include #include #include #include using namespace std; // add :: T -> T -> T // {v1,v2,...,vm}+vm+1 // bundle :: T -> T // u->{v1,v2,v3,...,vm} template vector free_tree_dp(const vector> &g, F1 add, F2 bundle) { const int n = g.size(); vector dp(n); function dfs = [&](int u, int p) { for (int v : g[u]) { if (v != p) { dfs(v, u); dp[u] = add(dp[u], dp[v]); } } dp[u] = bundle(dp[u]); }; dfs(0, -1); function dfs2 = [&](int u, int p) { const int m = g[u].size(); T l; vector r(m); for (int i = m - 2; i >= 0; i--) { r[i] = add(dp[g[u][i + 1]], r[i + 1]); } for (int i = 0; i < m; i++) { const int v = g[u][i]; dp[u] = bundle(add(l, r[i])); l = add(l, dp[v]); if (v != p) { dfs2(v, u); } } dp[u] = bundle(l); }; dfs2(0, -1); return dp; } int main() { int n; cin >> n; vector> g(n); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } auto add = [&](bool a, bool b) { return a || b; }; auto bundle = [&](bool a) { return !a; }; auto dp = free_tree_dp(g, add, bundle); cout << count(dp.begin(), dp.end(), true) << endl; for (int i = 0; i < n; i++) { if (dp[i]) { cout << i + 1 << endl; } } }