#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[100009];
void add(vector<int>& ret, vector<int> g) {
  for (int i = 0; i < g.size(); i++) ret.push_back(g[i]);
}
bool vis[100009], took[100009];
int solve(int ind, int parent, int take) {
  vis[ind] = 1;
  int ret = 0;
  for (int i = 0; i < v[ind].size(); i++) {
    int u = v[ind][i].first;
    if (u == parent || vis[u]) continue;
    ret |= solve(u, ind, v[ind][i].second);
  }
  if (ret == 0 && take == 2) {
    ret = 1;
    took[ind] = 1;
  }
  return ret;
}
int main() {
  int n, m, k, a, l, r, all, sk;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >> r >> a;
    v[l].push_back(pair<int, int>(r, a));
    v[r].push_back(pair<int, int>(l, a));
  }
  int ans = solve(1, 0, 0);
  int ret = 0;
  for (int i = 1; i <= n; i++)
    if (took[i]) ret++;
  cout << ret << endl;
  for (int i = 1; i <= n; i++)
    if (took[i]) cout << i << " ";
}
