#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
int w[100005], dp[100005];
void dfs(int node, int par) {
  dp[node] = w[node];
  for (int x : v[node]) {
    if (x == par) continue;
    dfs(x, node);
    dp[node] += dp[x];
  }
}
int main() {
  int n, i;
  cin >> n;
  for (i = 0; i < n - 1; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    v[x].push_back(y);
    v[y].push_back(x);
    if (c == 2) w[x] = w[y] = 1;
  }
  dfs(1, 0);
  vector<int> ans;
  for (i = 1; i <= n; i++)
    if (dp[i] == 1) ans.push_back(i);
  cout << ans.size() << "\n";
  for (auto x : ans) cout << x << " ";
}
