#include <bits/stdc++.h>
using namespace std;
struct edge {
  int v, k;
  edge(int _v, int _k) {
    v = _v;
    k = _k;
  }
};
const int N = 1e5 + 5;
int n, ptr[N], f[N], par[N];
vector<edge> a[N];
vector<int> vec;
void enter() {
  scanf("%d", &n);
  for (int(i) = (1), _b = (n - 1); (i) <= _b; ++(i)) {
    int u, v, k;
    scanf("%d%d%d", &u, &v, &k);
    a[u].push_back(edge(v, k));
    a[v].push_back(edge(u, k));
  }
}
void dfs() {
  vector<int> stk;
  par[1] = -1;
  f[1] = 0;
  stk.push_back(1);
  while (!stk.empty()) {
    int u = stk.back();
    if (ptr[u] == a[u].size()) {
      for (int(i) = (0), _b = (a[u].size() - 1); (i) <= _b; ++(i)) {
        int v = a[u][i].v;
        if (par[v] == u) {
          f[u] += (f[v] == 0 && a[u][i].k == 2) ? f[v] + 1 : f[v];
          if (f[v] == 0 && a[u][i].k == 2) vec.push_back(v);
        }
      }
      ptr[u] = 0;
      stk.pop_back();
      continue;
    }
    for (; ptr[u] < a[u].size();) {
      int v = a[u][ptr[u]++].v;
      if (!par[v]) {
        par[v] = u;
        stk.push_back(v);
        break;
      }
    }
  }
}
void solve() {
  dfs();
  printf("%d\n", (int)vec.size());
  for (int(i) = (0), _b = (vec.size() - 1); (i) <= _b; ++(i))
    printf("%d ", vec[i]);
}
int main() {
  enter();
  solve();
}
