#include <bits/stdc++.h>
using namespace std;
const long long mx = 1000 * 1000 + 5;
vector<pair<long long, long long> > ad[mx];
long long dp[mx];
vector<long long> ans;
void dfs(long long v, long long p) {
  for (auto u : ad[v]) {
    if (u.first == p) continue;
    dfs(u.first, v);
    dp[v] += dp[u.first];
    if (u.second && !dp[u.first]) {
      dp[v]++;
      ans.push_back(u.first);
    }
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, u, v, t;
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    cin >> u >> v >> t;
    u--, v--, t--;
    ad[u].push_back({v, t});
    ad[v].push_back({u, t});
  }
  dfs(0, 0);
  cout << dp[0] << endl;
  for (auto x : ans) cout << x + 1 << " ";
  cout << endl;
  return 0;
}
