#include <bits/stdc++.h>
using namespace std;
struct data {
  int u, level;
  bool operator<(const data &d) const { return level < d.level; }
  data(int x, int y) {
    u = x;
    level = y;
  }
};
priority_queue<struct data> q;
vector<int> A[100100], poor[100100];
int parent[100100], visited[100100], done[100100], needed[100100];
void dfs(int u, int l) {
  int i, v;
  visited[u] = true;
  q.push(data(u, l));
  for (i = 0; i < A[u].size(); i++) {
    v = A[u][i];
    if (!visited[v]) {
      if (poor[u][i] == 2) needed[v] = true;
      parent[v] = u;
      dfs(v, l + 1);
    }
  }
}
int main() {
  int i, j, k, n, p, t;
  scanf("%d", &n);
  for (i = 0; i < n - 1; i++) {
    scanf("%d%d%d", &j, &k, &t);
    A[j].push_back(k);
    A[k].push_back(j);
    poor[j].push_back(t);
    poor[k].push_back(t);
  }
  for (i = 0; i <= n; i++) {
    parent[i] = -1;
    visited[i] = false;
    done[i] = false;
    needed[i] = false;
  }
  dfs(1, 0);
  struct data r(0, 0);
  vector<int> ans;
  while (!q.empty()) {
    r = q.top();
    if (needed[r.u] == true) {
      if (done[r.u]) {
        if (r.u != 1) done[parent[r.u]] = true;
      } else {
        if (r.u != 1) {
          ans.push_back(r.u);
          done[parent[r.u]] = true;
        }
      }
    } else if (done[r.u] && r.u != 1)
      done[parent[r.u]] = true;
    q.pop();
  }
  printf("%d\n", ans.size());
  for (i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
  printf("\n");
  ;
  return 0;
}
