#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;
};
set<int> elected_cities;
struct city;
city* cities[100000];
struct city {
  city(int index) {
    this->parent_road = road();
    this->in_tree = false;
    this->index = index;
  }
  road parent_road;
  list<road> children;
  bool in_tree;
  int index;
  bool already_connected() {
    bool connected = false;
    for (list<road>::iterator it = this->children.begin();
         it != this->children.end(); ++it) {
      if (cities[it->destination_city]->already_connected()) {
        connected = true;
      }
    }
    if (!connected && this->parent_road.destination_city != -1 &&
        this->parent_road.problem) {
      connected = true;
      elected_cities.insert(this->index);
    }
    return connected;
  }
};
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);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  cities[0] = new city(0);
  for (int i = 0; i < n - 1; ++i) {
    int x, y, t;
    scanf("%d%d%d", &x, &y, &t);
    --x;
    --y;
    cities[i + 1] = new city(i + 1);
    edges[x].push_back(road(y, t == 2));
    edges[y].push_back(road(x, t == 2));
  }
  build_tree(0);
  cities[0]->already_connected();
  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;
}
