#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 7;
int n, p, q, r;
vector<pair<int, int> > v[N], vv;
int a[N];
int b[N];
int par[N];
void dfs(int x, int w, int c) {
  bool is_leaf = true;
  for (auto y : v[x]) {
    if (y.first != w) {
      is_leaf = false;
      par[y.first] = x;
      if (y.second == 2) {
        a[y.first] = 1;
        dfs(y.first, x, c + 1);
      } else
        dfs(y.first, x, c);
    }
  }
  if (is_leaf) vv.push_back({c, x});
}
int dfs2(int x) {
  if (b[x] || x == 1) return 0;
  int r = a[x];
  if (r == 1) b[x] = 1;
  r += dfs2(par[x]);
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> p >> q >> r;
    v[p].push_back({q, r});
    v[q].push_back({p, r});
  }
  dfs(1, 0, 0);
  sort(vv.begin(), vv.end(),
       [](pair<int, int> X, pair<int, int> Y) { return X.first > Y.first; });
  vector<int> ans;
  for (auto it : vv) {
    int dd = dfs2(it.second);
    if (dd) ans.push_back(it.second);
  }
  cout << ans.size() << '\n';
  for (auto it : ans) {
    cout << it << ' ';
  }
  return 0;
}
