#include <bits/stdc++.h>
const long long int MOD = 1e9 + 7;
const double PI = 22.0 / 7.0;
using namespace std;
long long int max(long long int a, long long int b) { return a >= b ? a : b; }
long long int min(long long int a, long long int b) { return a >= b ? b : a; }
long long int onBits(long long int n) { return __builtin_popcount(n); }
long long int power(long long int base, long long int exponent,
                    long long int modulus) {
  long long int result = 1;
  while (exponent > 0) {
    if (exponent % 2 == 1) result = (result * base) % modulus;
    exponent = exponent >> 1;
    base = (base * base) % modulus;
  }
  return result;
}
long long int fact[100100];
void factorial(long long int mod) {
  fact[0] = 1;
  for (long long int i = 1; i <= 100010; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
}
long long int nCr(long long int n, long long int r) {
  if (n < r) {
    return 0;
  }
  return fact[n] / (fact[n - r] * fact[r]);
}
long long int dx[4] = {0, 1, 0, -1};
long long int dy[4] = {-1, 0, 1, 0};
long long int i, j, test_case, test, x, y, k, n, m, a, b, c, d;
long long int testArray[10] = {5, 2, 3, 1, 8, 4, 9, 7, 6, 0};
struct P {
  long long int x, y;
  bool operator<(const P& t) const { return (this->x < t.x); }
};
map<long long int, long long int> vis;
vector<long long int> e[1001001];
long long int A[1001010] = {0};
map<long long int, long long int> mark;
long long int subtree[1001001] = {0};
void dfs(long long int x, long long int p) {
  long long int c = 0;
  if (mark[x] == 1) {
    c = 1;
  }
  for (auto v : e[x]) {
    if (v == p) {
      continue;
    }
    dfs(v, x);
    c += subtree[v];
  }
  subtree[x] = c;
}
void solve() {
  cin >> n;
  for (i = 0; i < n - 1; i++) {
    cin >> x >> y >> a;
    e[x].push_back(y);
    e[y].push_back(x);
    if (a == 2) {
      mark[x] = 1, mark[y] = 1;
    }
  }
  dfs(1, -1);
  long long int ans = 0;
  for (i = 1; i <= n; i++) {
    if (subtree[i] == 1) {
      ans++;
    }
  }
  cout << ans << '\n';
  for (i = 1; i <= n; i++) {
    if (subtree[i] == 1) {
      cout << i << " ";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  test_case = 1;
  while (test_case--) {
    solve();
  }
  return 0;
}
