#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector<pair<int, int> > adj[maxn];
bool mark[maxn];
vector<int> ans;
bool dfs(int v) {
  bool k = false;
  mark[v] = true;
  for (int i = 0; i < adj[v].size(); i++) {
    if (!mark[adj[v][i].first]) {
      if (dfs(adj[v][i].first))
        k = true;
      else if (adj[v][i].second == 2) {
        k = true;
        ans.push_back(adj[v][i].first);
      }
    }
  }
  return k;
}
int n, a, b, t;
bool f;
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b >> t;
    adj[a].push_back(make_pair(b, t));
    adj[b].push_back(make_pair(a, t));
  }
  f = dfs(1);
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  return 0;
}
