#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > tod[((int)1e5) + 10];
vector<int> res;
bool dfs(int nod, int peo, int ant) {
  bool si = false;
  for (int i = 0; i < tod[nod].size(); i++) {
    if (tod[nod][i].first != ant)
      si = dfs(tod[nod][i].first, tod[nod][i].second, nod) || si;
  }
  if (!si && peo == 2) {
    res.push_back(nod);
    si = true;
  };
  return si;
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int t1, t2, t3;
    cin >> t1 >> t2 >> t3;
    tod[t1 - 1].push_back(make_pair(t2 - 1, t3));
    tod[t2 - 1].push_back(make_pair(t1 - 1, t3));
  }
  for (int i = 0; i < tod[0].size(); i++)
    dfs(tod[0][i].first, tod[0][i].second, 0);
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); i++) cout << (res[i] + 1) << " ";
  cout << endl;
  return 0;
}
