#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n;
vector<pair<int, bool> > graph[MAXN];
vector<int> bois;
bool dfs(int u, int par) {
  bool containsBoi = false;
  for (auto adj : graph[u]) {
    int v = adj.first;
    bool isBroken = adj.second;
    if (v == par) continue;
    bool childHasBoi = dfs(v, u);
    if (childHasBoi) containsBoi = true;
    if (isBroken) {
      if (!childHasBoi) {
        bois.push_back(v);
        containsBoi = true;
      }
    }
  }
  return containsBoi;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int u, v, t;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v >> t;
    graph[u].push_back({v, t == 2});
    graph[v].push_back({u, t == 2});
  }
  dfs(1, 0);
  cout << bois.size() << "\n";
  for (auto b : bois) cout << b << " ";
  cout << "\n";
}
