#include <bits/stdc++.h>
using namespace std;
int n, x, y, t, i, viz[100001];
vector<int> a[100001];
map<pair<int, int>, int> mp;
vector<int> ans;
void dfs(int x, int y) {
  int i;
  for (i = 0; i < a[x].size(); i++)
    if (a[x][i] != y) dfs(a[x][i], x);
  if (!viz[x] && mp[{x, y}] == 2) viz[x]++, ans.push_back(x);
  viz[y] += viz[x];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> x >> y >> t;
    a[x].push_back(y);
    a[y].push_back(x);
    mp[make_pair(x, y)] = t;
    mp[make_pair(y, x)] = t;
  }
  dfs(1, 0);
  cout << ans.size() << endl;
  for (i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
