#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, head[200005], ne, st[200005], tp, deep[200005], fa[200005], vis[200005],
    ans[200005], cnt;
struct edge {
  int t, next, v;
} e[200005 * 2];
void Init(int u, int v, int w) {
  e[++ne].t = v;
  e[ne].next = head[u];
  head[u] = ne;
  e[ne].v = w;
}
void Insert(int u, int v, int w) {
  Init(u, v, w);
  Init(v, u, w);
}
void Dfs(int u, int f) {
  int cnt = 0;
  fa[u] = f;
  for (int k = head[u]; k; k = e[k].next) {
    int v = e[k].t;
    if (f == v) continue;
    cnt++;
    deep[v] = deep[u] + 1;
    Dfs(v, u);
    if (e[k].v == 2) st[++tp] = v;
  }
}
void Up_date(int x) {
  vis[x] = 1;
  while (fa[x] != 0 && !vis[fa[x]]) {
    x = fa[x];
    vis[x] = 1;
  }
}
bool cmp(int x, int y) { return deep[x] > deep[y]; }
int main() {
  n = read();
  memset(st, 0, sizeof(st));
  tp = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n - 1; i++) {
    int x = read(), y = read(), z = read();
    Insert(x, y, z);
  }
  Dfs(1, 0);
  sort(st + 1, st + 1 + tp, cmp);
  for (int i = 1; i <= tp; i++) {
    if (!vis[st[i]]) {
      ans[++cnt] = st[i];
      Up_date(st[i]);
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) printf("%d ", ans[i]);
  puts("");
  return 0;
}
