#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e5 + 5;
ll n;
vector<ll> adj[N];
ll white[N] = {0};
ll d[N] = {0};
void dfs(ll node, ll par) {
  if (white[node] == 1) {
    d[node] = 1;
  }
  for (ll u : adj[node]) {
    if (u != par) {
      dfs(u, node);
      d[node] = d[node] + d[u];
    }
  }
}
signed main() {
  cin >> n;
  for (ll i = 1; i < n; i++) {
    ll x, y, type;
    cin >> x >> y >> type;
    adj[x].push_back(y);
    adj[y].push_back(x);
    if (type == 2) {
      white[x] = 1;
      white[y] = 1;
    }
  }
  dfs(1, -1);
  vector<ll> res;
  for (ll i = 1; i <= n; i++) {
    if (white[i] && d[i] == 1) {
      res.push_back(i);
    }
  }
  cout << res.size() << "\n";
  for (ll i = 0; i < res.size(); i++) {
    cout << res[i] << " ";
  }
  cout << "\n";
  return 0;
}
