#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<pair<int, int> > adj[N];
vector<int> ret;
bool dfs(int x, int p, bool is) {
  int a, i;
  bool R = is, t;
  for (i = 0; i < adj[x].size(); ++i) {
    a = adj[x][i].first;
    if (a != p) {
      is |= adj[x][i].second;
      R |= adj[x][i].second;
      if ((t = dfs(a, x, adj[x][i].second))) {
        is = 0;
      }
      R |= t;
    }
  }
  if (is) ret.push_back(x);
  return R;
}
int main() {
  int b, n, i, a, t;
  scanf("%d", &n);
  for (i = 0; i < n - 1; ++i) {
    scanf("%d%d%d", &a, &b, &t);
    --t;
    adj[a].push_back(make_pair(b, t));
    adj[b].push_back(make_pair(a, t));
  }
  dfs(1, 0, 0);
  cout << ret.size() << endl;
  for (i = 0; i < ret.size(); ++i) cout << ret[i] << " ";
  cout << endl;
}
