#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int n, cnt[MAXN];
vector<int> res;
vector<pair<int, int>> g[MAXN];
void dfs(int u, int p) {
  for (pair<int, int> nxt : g[u]) {
    int v = nxt.first;
    bool broken = nxt.second == 2;
    if (v == p) continue;
    dfs(v, u);
    if (cnt[v] == 0 && broken) {
      res.push_back(v);
    }
    cnt[u] += cnt[v] + broken;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    g[u].push_back({v, c});
    g[v].push_back({u, c});
  }
  dfs(1, -1);
  cout << (int)res.size() << '\n';
  for (int u : res) {
    cout << u << ' ';
  }
  return 0;
}
