#include <bits/stdc++.h>
using namespace std;
int mk[100005];
vector<int> a[100005];
int n;
int ans[100005], l;
int dfs(int fa, int t) {
  int sum = 0;
  int sz = a[t].size();
  for (int i = 0; i < sz; i += 2) {
    int node = a[t][i];
    int k = a[t][i + 1];
    if (node != fa) {
      sum += dfs(t, node) + (k == 2 ? 1 : 0);
    }
  }
  if (sum == 0) mk[t] = 1;
  return sum;
}
int dfs1(int fa, int t) {
  int sum = 0;
  int sz = a[t].size();
  for (int i = 0; i < sz; i += 2) {
    int node = a[t][i];
    int k = a[t][i + 1];
    if (node != fa) {
      if (mk[node] == 1) {
        if (k == 2) {
          sum++;
          ans[l++] = node;
        }
      } else {
        sum += dfs1(t, node);
      }
    }
  }
  return sum;
}
int main() {
  while (scanf("%d", &n) + 1) {
    for (int i = 0; i < n; i++)
      if (!a[i].empty()) a[i].clear();
    for (int i = 1; i < n; i++) {
      int x, y, t;
      scanf("%d%d%d", &x, &y, &t);
      a[x].push_back(y);
      a[x].push_back(t);
      a[y].push_back(x);
      a[y].push_back(t);
    }
    memset(mk, 0, sizeof(mk));
    if (dfs(-1, 1) == 0) {
      printf("0\n");
    } else {
      l = 0;
      dfs1(-1, 1);
      printf("%d\n", l);
      sort(ans, ans + l);
      for (int i = 0; i < l; i++)
        printf("%d%c", ans[i], i == l - 1 ? '\n' : ' ');
    }
  }
  return 0;
}
