#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[100001];
bool vis[100001];
bool dfs(int x, int p = -1, int in = -1) {
  vis[x] = true;
  int l = adj[x].size();
  vector<pair<int, int> > &v = adj[x];
  for (__typeof(l) i = (0) - ((0) > (l)); i != (l) - ((0) > (l));
       i += 1 - 2 * ((0) > (l))) {
    if (!vis[v[i].first])
      if (dfs(v[i].first, x, i) && v[i].second == 1) v[i].first = -1;
  }
  long long cnt = 0;
  for (__typeof(l) i = (0) - ((0) > (l)); i != (l) - ((0) > (l));
       i += 1 - 2 * ((0) > (l))) {
    if (v[i].first != -1 && v[i].first != p) return false;
  }
  return true;
}
vector<int> vec;
void dfs2(int x) {
  vis[x] = true;
  int l = adj[x].size();
  vector<pair<int, int> > &v = adj[x];
  int cnt = 0;
  for (__typeof(l) i = (0) - ((0) > (l)); i != (l) - ((0) > (l));
       i += 1 - 2 * ((0) > (l))) {
    if (v[i].first > 0 && !vis[v[i].first] && ++cnt) dfs2(v[i].first);
  }
  if (!cnt) vec.push_back(x);
}
signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    int n, x, y, t;
    cin >> n;
    for (__typeof(n - 1) i = (0) - ((0) > (n - 1));
         i != (n - 1) - ((0) > (n - 1)); i += 1 - 2 * ((0) > (n - 1))) {
      cin >> x >> y >> t;
      adj[x].push_back({y, t});
      adj[y].push_back({x, t});
    }
    bool flag = dfs(1);
    if (flag) {
      cout << 0;
      return 0;
    }
    for (__typeof(100001) i = (0) - ((0) > (100001));
         i != (100001) - ((0) > (100001)); i += 1 - 2 * ((0) > (100001)))
      vis[i] = false;
    dfs2(1);
    cout << vec.size() << '\n';
    for (__typeof(vec.size()) i = (0) - ((0) > (vec.size()));
         i != (vec.size()) - ((0) > (vec.size()));
         i += 1 - 2 * ((0) > (vec.size())))
      cout << vec[i] << " ";
  }
  return 0;
}
