#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 100010;
int n, m, x, y, t, white[MAX], d[MAX];
vector<int> g[MAX];
void dfs(int v, int prev) {
  d[v] = white[v];
  for (int i = 0, _n = ((int)(g[v]).size()); i < _n; ++i) {
    int to = g[v][i];
    if (prev == to) continue;
    dfs(to, v);
    d[v] += d[to];
  }
}
int main() {
  scanf("%d", &(n));
  for (int i = 1, _n = (n); i < _n; ++i) {
    scanf("%d", &(x));
    scanf("%d", &(y));
    scanf("%d", &(t));
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
    if (t == 2) {
      white[x] = 1;
      white[y] = 1;
    }
  }
  dfs(0, -1);
  vector<int> ans;
  for (int i = 0, _n = (n); i < _n; ++i) {
    if (white[i] && d[i] == 1) ans.push_back(i + 1);
  }
  cout << (int)(ans).size() << endl;
  for (int i = 0, _n = ((int)(ans).size()); i < _n; ++i) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
