#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<pair<int, int>> g[N];
int used[N];
int n;
bool dfs(int v, int b, vector<int>& r) {
  used[v] = true;
  vector<int> y;
  bool ins = false;
  for (auto [u, t] : g[v]) {
    if (!used[u]) {
      ins |= dfs(u, t == 2, r);
    }
  }
  if (!ins && b) {
    r.push_back(v);
    return true;
  }
  return ins;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v, t;
    cin >> u >> v >> t;
    g[u].push_back({v, t});
    g[v].push_back({u, t});
  }
  vector<int> res;
  dfs(1, 0, res);
  cout << res.size() << endl;
  for (int i : res) {
    cout << i << " ";
  }
  cout << endl;
  return 0;
}
