#include <bits/stdc++.h>
using namespace std;
int n;
int d[200002];
vector<pair<int, int> > g[200002];
vector<int> ans;
inline int dfs(int v, int pr) {
  d[v] = 0;
  for (int i = 0; i < (int(g[v].size())); ++i) {
    int v2 = g[v][i].first;
    int cost = g[v][i].second;
    if (v2 == pr) continue;
    d[v] += dfs(v2, v);
    if (!d[v2] && cost == 2) {
      ans.push_back(v2);
      d[v]++;
    }
  }
  return d[v];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int v1, v2, cost;
    scanf("%d%d%d", &v1, &v2, &cost);
    --v1, --v2;
    g[v1].push_back(make_pair(v2, cost));
    g[v2].push_back(make_pair(v1, cost));
  }
  cout << dfs(0, -1) << endl;
  for (int i = 0; i < (int(ans.size())); ++i)
    printf("%d%c", ans[i] + 1, " \n"[i + 1 == (int(ans.size()))]);
  return 0;
}
