#include <bits/stdc++.h>
using namespace std;
int n, u[1111111], ok = 1, d[1111111];
vector<pair<int, int> > a[1111111];
vector<int> b;
void dfs(int x, int c, int p) {
  u[x] = 1;
  for (int i = 0; i < a[x].size(); i++) {
    int v = a[x][i].first, k = a[x][i].second;
    if (!u[v]) dfs(v, k, x);
  }
  if (c == 1 && !d[x]) {
    b.push_back(x);
    d[x] = 1;
  }
  d[p] = max(d[p], d[x]);
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int x, y, t;
    cin >> x >> y >> t;
    x--, y--, t--;
    a[x].push_back(make_pair(y, t));
    a[y].push_back(make_pair(x, t));
  }
  dfs(0, -1, -1);
  cout << b.size() << endl;
  for (int i = 0; i < b.size(); i++) cout << b[i] + 1 << " ";
  return 0;
}
