#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
vector<pair<int, int> > v[100005];
vector<int> ans;
bool dfs(int s, int p = 0) {
  bool op = false;
  for (int i = 0; i < v[s].size(); i++) {
    int x = v[s][i].first;
    if (x == p) {
      continue;
    }
    bool track = dfs(x, s);
    bool j = false;
    if (v[s][i].second == 2) j = true;
    if (!track) {
      if (j) {
        ans.push_back(x);
        op = 1;
      }
    } else {
      op = 1;
    }
  }
  return op;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b, d;
    cin >> a >> b >> d;
    v[a].push_back({b, d});
    v[b].push_back({a, d});
  }
  dfs(1);
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
}
