#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e17 + 7;
const long long MOD = 1e7 + 9;
const long long N = 1e5 + 9;
vector<vector<pair<long long, bool>>> edg(N);
bool prob[N] = {0}, visit[N] = {0};
void dfs(long long x, long long last) {
  long long temp;
  for (auto i : edg[x]) {
    if (visit[i.first]) continue;
    visit[i.first] = true;
    temp = last;
    if (i.second) {
      prob[temp] = false;
      temp = i.first;
      prob[temp] = true;
    }
    dfs(i.first, temp);
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n;
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long x, y, p;
    cin >> x >> y >> p;
    edg[x].push_back({y, p - 1});
    edg[y].push_back({x, p - 1});
  }
  visit[1] = true;
  dfs(1, 0);
  vector<long long> ans;
  for (long long i = 1; i <= n; i++) {
    if (prob[i]) ans.push_back(i);
  }
  cout << ans.size() << "\n";
  for (auto i : ans) cout << i << " ";
  cout << "\n";
  return 0;
}
