#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, bool> > > A;
vector<int> ans;
int Color[100001];
int Marc[100001];
bool dfs(int u) {
  Color[u] = 1;
  bool m = 0;
  for (int i = 0; i < A[u].size(); i++) {
    pair<int, bool> v = A[u][i];
    if (Color[v.first] == 0) {
      Marc[v.first] = dfs(v.first);
      if (v.second) {
        m = 1;
        if (Marc[v.first] == 0) {
          ans.push_back(v.first + 1);
        }
      } else {
        if (Marc[v.first] == 1) {
          m = 1;
        }
      }
    }
  }
  Color[u] = 2;
  return m;
}
int main() {
  int v;
  cin >> v;
  A.resize(v);
  for (int i = 1; i < v; i++) {
    int v1, v2, e;
    cin >> v1 >> v2 >> e;
    A[v2 - 1].push_back(make_pair(v1 - 1, e - 1));
    A[v1 - 1].push_back(make_pair(v2 - 1, e - 1));
  }
  dfs(0);
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
