#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200000];
set<int> prob[200000];
int counter[200000];
bool vis[200000];
vector<int> res;
bool white[200000];
int flood(int ind) {
  vis[ind] = 1;
  for (int i = 0; i < (int)adj[ind].size(); i++) {
    int j = adj[ind][i];
    if (vis[j]) continue;
    int x = 0;
    if (prob[ind].count(j)) x = 1;
    counter[ind] += flood(j) + x;
  }
  return counter[ind];
}
int main() {
  int n, x, y, t;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d%d", &x, &y, &t);
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
    if (t == 2) {
      prob[x].insert(y);
      prob[y].insert(x);
      white[x] = 1;
      white[y] = 1;
    }
  }
  flood(0);
  for (int i = 0; i < n; i++) {
    if (counter[i] == 0 && white[i]) res.push_back(i);
  }
  printf("%d\n", (int)res.size());
  for (int i = 0; i < (int)res.size(); i++) {
    printf("%d", res[i] + 1);
    if (i == (int)res.size() - 1)
      printf("\n");
    else
      printf(" ");
  }
}
