#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
long long int a[N], b[N], c[N], h[N], e, mx, fa[N];
set<long long int> t[N], ans;
vector<pair<long long int, long long int> > v[N];
bool viz[N], re[N];
void dfs(long long int x, long long int par) {
  fa[x] = par;
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i].first != par) {
      h[v[x][i].first] = h[x] + 1;
      if (v[x][i].second == 2) {
        mx = max(mx, h[v[x][i].first]);
        t[h[v[x][i].first]].insert(v[x][i].first);
      }
      dfs(v[x][i].first, x);
    }
  }
}
void rep(long long int x, long long int k) {
  while (k >= 1) {
    if (re[x] == true) break;
    re[x] = true;
    t[k].erase(x);
    x = fa[x];
    k--;
  }
}
int main() {
  ios::sync_with_stdio(0);
  long long int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    if (c[i] == 2) e++;
    v[a[i]].push_back(make_pair(b[i], c[i]));
    v[b[i]].push_back(make_pair(a[i], c[i]));
  }
  if (e == 0) {
    cout << 0;
    return 0;
  }
  dfs(0, -1);
  for (int i = mx; i >= 1; i--) {
    while (t[i].size() != 0) {
      long long int q = *t[i].begin();
      rep(q, i);
      ans.insert(q + 1);
    }
  }
  set<long long int>::iterator it;
  cout << ans.size() << '\n';
  for (it = ans.begin(); it != ans.end(); it++) {
    cout << *it << ' ';
  }
}
