#include <bits/stdc++.h>
using namespace std;
vector<int> dp(100001), ans;
vector<int> adj[100001];
vector<int> color(100001, 0);
void solve(int v, int prev) {
  dp[v] = 0;
  if (color[v]) dp[v] = 1;
  for (int x : adj[v]) {
    if (x != prev) {
      solve(x, v);
      dp[v] += dp[x];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, a, b, c;
  cin >> n;
  for (int i = 1; i <= n - 1; ++i) {
    cin >> a >> b >> c;
    adj[a].push_back(b);
    adj[b].push_back(a);
    if (!color[a]) color[a] = c - 1;
    if (!color[b]) color[b] = c - 1;
  }
  solve(1, -1);
  for (int i = 1; i <= n; ++i)
    if (color[i] && dp[i] == 1) ans.push_back(i);
  cout << ans.size() << endl;
  for (int x : ans) cout << x << " ";
  cout << endl;
  return 0;
}
