#include <bits/stdc++.h>
using namespace std;
int a, b, c, n;
vector<pair<int, int> > v[(int)(2e5 + 10)];
vector<int> cvp;
bool dfs(int x, int ata, int bozukmu) {
  bool flag = false;
  for (int i = 0; i <= v[x].size() - 1; i++) {
    if (v[x][i].first != ata && dfs(v[x][i].first, x, v[x][i].second))
      flag = true;
  }
  if (bozukmu == 2 && !flag) {
    flag = true;
    cvp.push_back(x);
  }
  return flag;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d %d %d", &a, &b, &c);
    v[a].push_back(make_pair(b, c));
    v[b].push_back(make_pair(a, c));
  }
  dfs(1, 0, 0);
  cout << cvp.size() << '\n';
  if (cvp.size())
    for (int i = 0; i <= cvp.size() - 1; i++) printf("%d ", cvp[i]);
}
