#include <bits/stdc++.h>
using namespace std;
long long c = 0;
bool vis[500007];
vector<long long> v[500007];
long long d[500007];
map<pair<long long, long long>, long long> m;
vector<long long> vans;
void dfs(long long node) {
  vis[node] = 1;
  for (auto child : v[node]) {
    if (!vis[child]) {
      dfs(child);
      if (m[{node, child}] > 0) {
        if (d[child] == 0) {
          d[node]++;
          vans.push_back(child);
        } else
          d[node] += d[child];
      } else
        d[node] += d[child];
    }
  }
}
void solve() {
  long long i, j, k, l, t, n, x, y, r, q, n1;
  cin >> n;
  for (i = 0; i < n - 1; i++) {
    cin >> x >> y >> k;
    v[x].push_back(y);
    v[y].push_back(x);
    if (k == 2) {
      m[{x, y}] = 1;
      m[{y, x}] = 1;
    }
  }
  dfs(1);
  cout << vans.size() << "\n";
  for (auto it : vans) cout << it << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
}
