#include <bits/stdc++.h>
using namespace std;
long long n;
long long vis[100500];
long long par[100500];
vector<long long> g[100500];
void dfs(long long v, long long pr) {
  if (pr != -1) par[v] = pr;
  for (auto u : g[v]) {
    if (u == pr) continue;
    dfs(u, v);
  }
}
void SOLVE() {
  fill(par, par + 100500, -1);
  cin >> n;
  vector<pair<long long, long long> > bad;
  for (long long i = 1; i < n; i++) {
    long long v, u, t;
    cin >> v >> u >> t;
    v--, u--;
    g[v].push_back(u);
    g[u].push_back(v);
    if (t == 2) bad.push_back({v, u});
  }
  dfs(0, -1);
  for (auto now : bad) {
    long long v = now.first, u = now.second;
    if (par[v] == u) swap(u, v);
    assert(par[u] == v);
    while (par[u] != -1 && !vis[u]) {
      vis[u] = 1;
      u = par[u];
    }
  }
  vector<long long> ans;
  for (long long i = 0; i < n; i++) {
    if (!vis[i]) continue;
    long long fl = 0;
    for (auto u : g[i]) {
      if (u == par[i]) continue;
      if (vis[u]) fl = 1;
    }
    if (!fl) ans.push_back(i);
  }
  cout << ans.size() << '\n';
  for (auto now : ans) cout << now + 1 << ' ';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout.precision(10);
  long long Q = 1;
  while (Q--) {
    SOLVE();
  }
  return 0;
}
