#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[100000];
int vis[100000];
set<int> res;
int dfs(int i) {
  vis[i] = 1;
  int val = 0, cnt;
  for (int j = 0; j < g[i].size(); ++j) {
    int v = g[i][j].first;
    int t = g[i][j].second;
    if (vis[v] == false) {
      cnt = dfs(v);
      if (t == 2) {
        val++;
        if (!cnt) res.insert(v);
      }
      val += cnt;
    }
  }
  return val;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v, t;
    scanf("%d%d%d", &u, &v, &t);
    g[u].push_back(make_pair(v, t));
    g[v].push_back(make_pair(u, t));
  }
  dfs(1);
  printf("%d\n", (int)res.size());
  for (set<int>::iterator it = res.begin(); it != res.end(); ++it)
    printf("%d ", (*it));
  printf("\n");
  return 0;
}
