#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, e;
int last[N];
int prec[N];
int to[N];
int kind[N];
void add(int x, int y, int k) {
  prec[e] = last[x];
  last[x] = e;
  to[e] = y;
  kind[e] = k;
  e += 1;
}
vector<int> ans;
int dfs(int x, int p) {
  int ret = 0;
  for (int i = last[x]; i != -1; i = prec[i]) {
    int y = to[i];
    if (y == p) continue;
    if (dfs(y, x))
      ret = 1;
    else if (kind[i] == 2) {
      ans.push_back(y);
      ret = 1;
    }
  }
  return ret;
}
int main(void) {
  memset(last, -1, sizeof(last));
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int x, y, t;
    cin >> x >> y >> t;
    add(x, y, t);
    add(y, x, t);
  }
  dfs(1, -1);
  cout << (int)ans.size() << endl;
  for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
