#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[100005];
bool visit[100005];
int n;
vector<int> ans;
bool dfs(int i, int last) {
  visit[i] = true;
  bool flag = false;
  for (int j = 0; j < v[i].size(); j++) {
    if (!visit[v[i][j].first]) {
      if (v[i][j].second == 2)
        flag = flag | dfs(v[i][j].first, v[i][j].first);
      else
        flag = flag | dfs(v[i][j].first, 0);
    }
  }
  if (flag == false && last != 0) {
    flag = true;
    ans.push_back(i);
  }
  return flag;
}
void Readinput() {
  int i, x, y, t;
  scanf("%d", &n);
  for (i = 0; i < n - 1; i++) {
    scanf("%d", &x);
    scanf("%d", &y);
    scanf("%d", &t);
    v[x].push_back(pair<int, int>(y, t));
    v[y].push_back(pair<int, int>(x, t));
  }
}
void solve() {
  int i, j;
  dfs(1, 0);
  cout << ans.size() << endl;
  for (i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << endl;
}
int main() {
  memset(visit, false, sizeof(visit));
  Readinput();
  solve();
  return 0;
}
