#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ar[n + 1];
  long long i;
  for (i = 1; i <= n; i++) ar[i] = -1;
  vector<pair<long long, long long>> br[n + 1];
  set<pair<long long, long long>> st;
  for (i = 0; i < n - 1; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    br[a].push_back({b, c});
    br[b].push_back({a, c});
    if (c == 2) {
      st.insert({a, b});
      st.insert({b, a});
    }
  }
  stack<long long> s1;
  s1.push(1);
  long long par[n + 1];
  par[1] = -1;
  long long vis[n + 1];
  for (i = 0; i <= n; i++) {
    vis[i] = -1;
  }
  long long outdeg[n + 1];
  for (i = 1; i <= n; i++) outdeg[i] = 0;
  vis[1] = 1;
  queue<long long> q;
  while (!s1.empty()) {
    long long r = s1.top();
    s1.pop();
    long long u = 0;
    for (pair<long long, long long> p : br[r]) {
      long long g = p.first;
      if (vis[g] == -1) {
        u++;
        outdeg[r]++;
        vis[g] = 1;
        par[g] = r;
        s1.push(g);
      }
    }
    if (u == 0) {
      q.push(r);
    }
  }
  long long dr[n + 1];
  for (i = 1; i <= n; i++) dr[i] = -1;
  long long sum = 0;
  while (!q.empty()) {
    long long e = q.front();
    q.pop();
    if (par[e] != -1) {
      long long u = par[e];
      if (dr[e] == -1 and st.find({u, e}) != st.end()) {
        sum++;
        ar[e] = 1;
        dr[u] = 1;
      } else if (dr[e] == 1) {
        dr[u] = 1;
      }
      outdeg[u]--;
      if (outdeg[u] == 0) q.push(u);
    }
  }
  cout << sum << "\n";
  for (i = 1; i <= n; i++) {
    if (ar[i] == 1) cout << i << " ";
  }
}
