#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 228228;
vector<long long> o, a[N], b[N];
long long x, y, c, i, j, ot = -1, n, m, t[2][N * 4], d[N];
long long rec(long long v, long long pr, long long e, long long w) {
  long long t, k = 0, q = 0;
  for (int i = 0; i < a[v].size(); i++)
    if (a[v][i] != pr)
      q++, t = rec(a[v][i], v, e + b[v][i], b[v][i]) + b[v][i], k += t;
  if (!k && e && ((!q && w) || w)) o.push_back(v + 1);
  return k;
}
int main() {
  cin >> n;
  for (i = 0; i < n - 1; i++)
    cin >> x >> y >> c, x--, y--, a[x].push_back(y), b[x].push_back(c - 1),
        a[y].push_back(x), b[y].push_back(c - 1);
  rec(0, -1, 0, 0);
  cout << o.size() << "\n";
  for (i = 0; i < o.size(); i++) cout << o[i] << " ";
}
