#include <bits/stdc++.h>
using namespace std;
long long gcd(int a, int b) {
  if (!b) return a;
  return gcd(b, a % b);
}
vector<pair<long long, long long> > mat[100005];
long long vis[100005];
long long curr[100005];
vector<long long> s;
long long ans = 0;
int dfs(long long i, long long c) {
  int ret = 0;
  vis[i] = 1;
  int sz = mat[i].size();
  for (int(j) = (0); (j) < (sz); (j)++) {
    int p = mat[i][j].first;
    int q = mat[i][j].second;
    if (p != c) {
      int temp = dfs(p, i);
      ret += temp;
      if (q == 2 && temp == 0) {
        ret++;
        s.push_back(p);
      }
    }
  }
  return ret;
}
int main() {
  long long n;
  cin >> n;
  for (int(i) = (0); (i) < (n - 1); (i)++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    mat[a].push_back(make_pair(b, c));
    mat[b].push_back(make_pair(a, c));
  }
  int ans = dfs(0, -1);
  cout << ans << endl;
  for (int(i) = (0); (i) < (s.size()); (i)++) cout << s[i] + 1 << " ";
  return 0;
}
