#include <bits/stdc++.h>
using namespace std;
struct road {
  road() {
    this->problem = false;
    this->destination_city = -1;
  }
  road(int dest, bool prob) {
    this->destination_city = dest;
    this->problem = prob;
  }
  int destination_city;
  bool problem;
};
struct city {
  city() {
    this->parent_road = road();
    this->in_tree = false;
  }
  road parent_road;
  list<road> children;
  bool in_tree;
};
city cities[100000];
list<road> edges[100000];
void build_tree(int index) {
  cities[index].in_tree = true;
  for (list<road>::iterator it = edges[index].begin(); it != edges[index].end();
       ++it) {
    if (cities[it->destination_city].in_tree) {
      continue;
    }
    cities[it->destination_city].parent_road = road(index, it->problem);
    cities[index].children.push_back(*it);
    build_tree(it->destination_city);
  }
}
set<int> elected_cities;
bool already_connected(int index) {
  bool connected = false;
  for (list<road>::iterator it = cities[index].children.begin();
       it != cities[index].children.end(); ++it) {
    if (already_connected(it->destination_city)) {
      connected = true;
    }
  }
  if (!connected && cities[index].parent_road.destination_city != -1 &&
      cities[index].parent_road.problem) {
    connected = true;
    elected_cities.insert(index);
  }
  return connected;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int x, y, t;
    scanf("%d%d%d", &x, &y, &t);
    --x;
    --y;
    edges[x].push_back(road(y, t == 2));
    edges[y].push_back(road(x, t == 2));
  }
  build_tree(0);
  already_connected(0);
  printf("%d\n", (int)elected_cities.size());
  for (set<int>::iterator it = elected_cities.begin();
       it != elected_cities.end(); ++it) {
    printf("%d ", *it + 1);
  }
  printf("\n");
  return 0;
}
