#include <bits/stdc++.h>
using namespace std;
const int sz = 1e5 + 10;
vector<pair<int, int> > adj[sz];
int dp[sz], fl[sz];
void dfs(int u, int p, int prob) {
  dp[u] = fl[u];
  for (auto it : adj[u]) {
    if (it.first == p) continue;
    dfs(it.first, u, it.second == 2);
    dp[u] += dp[it.first];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, x, y, t;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y >> t;
    adj[x].push_back(pair<int, int>(y, t));
    adj[y].push_back(pair<int, int>(x, t));
    if (t == 2) fl[x] = fl[y] = 1;
  }
  dfs(1, -1, 0);
  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (dp[i] == 1 && fl[i]) ans.push_back(i);
  }
  cout << ans.size() << "\n";
  for (auto it : ans) cout << it << " ";
  cout << "\n";
  return 0;
}
