#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 10, INF = 1e18;
int T, c;
const int mod = 1e9 + 7;
int n;
vector<pair<int, bool> > g[N];
vector<int> subset, color(N, 0);
bool dfs(int u, bool is_problem) {
  color[u] = 1;
  bool new_problem = false;
  for (auto p : g[u]) {
    int v = p.first;
    if (!color[v]) {
      new_problem |= dfs(v, p.second);
    }
  }
  if (!new_problem && is_problem) {
    subset.push_back(u);
    return true;
  }
  return new_problem;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, problem;
    cin >> u >> v >> problem;
    g[u].push_back({v, problem == 2});
    g[v].push_back({u, problem == 2});
  }
  dfs(1, false);
  cout << subset.size() << '\n';
  for (auto k : subset) cout << k << " ";
}
