#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int max(long long int a, long long int b) {
  if (a > b)
    return a;
  else
    return b;
}
long long int min(long long int a, long long int b) {
  if (a < b)
    return a;
  else
    return b;
}
long long int binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long binpow(long long a, long long b) {
  if (b == 0) return 1;
  long long res = binpow(a, b / 2);
  if (b % 2)
    return res * res * a;
  else
    return res * res;
}
vector<vector<pair<int, int>>> adj;
vector<int> dp;
vector<int> ans;
int dfs(int x, int p) {
  for (auto c : adj[x]) {
    if (c.first == p) continue;
    int val = dfs(c.first, x);
    if (val == 0 && c.second == 2) {
      dp[x] += val + 1;
      ans.push_back(c.first);
    } else {
      dp[x] += val;
    }
  }
  return dp[x];
}
void solve() {
  int n;
  cin >> n;
  adj.resize(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int x, y, t;
    cin >> x >> y >> t;
    adj[x].push_back({y, t});
    adj[y].push_back({x, t});
  }
  dp.resize(n + 1);
  dfs(1, 0);
  cout << dp[1] << endl;
  for (auto c : ans) {
    cout << c << " ";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
