#include <bits/stdc++.h>
using namespace std;
const int mx = 100005;
bool elect[mx];
vector<vector<pair<int, int> > > vec(mx);
void deepika(int u, int from, int prev) {
  int i, k, v, l = vec[u].size();
  for (i = 0; i < l; i++) {
    v = vec[u][i].first;
    k = vec[u][i].second;
    if (v != from) {
      if (k == 2) {
        elect[prev] = 0;
        elect[v] = 1;
        deepika(v, u, v);
      } else {
        deepika(v, u, prev);
      }
    }
  }
}
int main() {
  int n, i, j, k, u, v;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d %d %d", &u, &v, &k);
    vec[u].push_back(make_pair(v, k));
    vec[v].push_back(make_pair(u, k));
  }
  memset(elect, 0, sizeof(elect));
  deepika(1, 0, 0);
  k = 0;
  for (i = 1; i <= n; i++) {
    if (elect[i]) k++;
  }
  printf("%d\n", k);
  k = 0;
  for (i = 1; i <= n; i++) {
    if (elect[i]) {
      if (k) printf(" ");
      k = 1;
      printf("%d", i);
    }
  }
}
