#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, cnt;
int b[200005 << 1], p[200005], nextedge[200005 << 1], w[200005 << 1];
int ans[200005], deep[200005], dp[200005], flag[200005];
void add(int x, int y, int z) {
  cnt++;
  b[cnt] = y;
  nextedge[cnt] = p[x];
  p[x] = cnt;
  w[cnt] = z;
}
void anode(int x, int y, int z) {
  add(x, y, z);
  add(y, x, z);
}
void dfs(int x) {
  for (int i = p[x]; i; i = nextedge[i]) {
    int v = b[i];
    if (deep[v] || v == 1) continue;
    deep[v] = deep[x] + 1;
    if (w[i] == 2) flag[v] = 1;
    dfs(v);
  }
}
void DP(int x) {
  if (flag[x]) {
    bool f = true;
    for (int i = p[x]; i; i = nextedge[i]) {
      int v = b[i];
      if (deep[v] < deep[x]) continue;
      DP(v);
      if (dp[v]) f = false;
      dp[x] += dp[v];
    }
    if (f == true) {
      dp[x] = 1;
      ans[++ans[0]] = x;
    }
  } else {
    for (int i = p[x]; i; i = nextedge[i]) {
      int v = b[i];
      if (deep[v] < deep[x]) continue;
      DP(v);
      dp[x] += dp[v];
    }
  }
}
int main() {
  n = read();
  static int x, y, z;
  for (int i = 1; i < n; i++) {
    x = read(), y = read(), z = read();
    anode(x, y, z);
  }
  dfs(1);
  DP(1);
  printf("%d\n", ans[0]);
  for (int i = 1; i <= ans[0]; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
