#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, u, v, t, par[N], dep[N];
bool done[N];
vector<int> ans, nei[N];
vector<pair<int, int> > vec, VEC;
inline void fp(int v) {
  for (int i = 0; i < nei[v].size(); i++)
    if ((u = nei[v][i]) != par[v]) {
      dep[u] = dep[v] + 1;
      par[u] = v;
      fp(u);
    }
}
inline void bk(int v) {
  if (done[v]) return;
  done[v] = true;
  if (v) bk(par[v]);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v >> t;
    nei[--u].push_back(--v);
    nei[v].push_back(u);
    if (t - 1) vec.push_back(make_pair(u, v));
  }
  fp(0);
  for (int i = 0; i < vec.size(); i++) {
    u = vec[i].first;
    v = vec[i].second;
    par[u] == v ? VEC.push_back(make_pair(dep[u], u))
                : VEC.push_back(make_pair(dep[v], v));
  }
  sort(VEC.begin(), VEC.end());
  for (int i = VEC.size() - 1; i >= 0; i--)
    if (!done[VEC[i].second]) {
      v = VEC[i].second;
      ans.push_back(v + 1);
      bk(v);
    }
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << ' ';
  return 0;
}
