#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
bool check[maxn], checks[maxn];
vector<pair<int, int> > vec[maxn];
vector<int> ans;
int num[maxn];
void dfs_1(int cur) {
  check[cur] = 1;
  for (int i = 0; i < (int)vec[cur].size(); i++) {
    int nei = vec[cur][i].first;
    int yal = vec[cur][i].second;
    if (!check[nei]) {
      num[cur] += yal;
      dfs_1(nei);
      num[cur] += num[nei];
      if (num[nei] == 0 && !yal)
        vec[cur][i].second = 0;
      else
        vec[cur][i].second = 1;
    }
  }
}
void dfs_2(int cur) {
  checks[cur] = 1;
  bool t = false;
  for (int i = 0; i < (int)vec[cur].size(); i++) {
    int nei = vec[cur][i].first;
    bool yal = vec[cur][i].second;
    if (!checks[nei] && yal) {
      t = 1;
      dfs_2(nei);
    }
  }
  if (!t && cur != 1) ans.push_back(cur);
}
int main() {
  int n, m, f, g, c, d, s;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> f >> g >> c;
    vec[f].push_back(make_pair(g, c - 1));
    vec[g].push_back(make_pair(f, c - 1));
  }
  dfs_1(1);
  dfs_2(1);
  cout << (int)ans.size() << endl;
  for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << " ";
}
