#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> g[100005];
int n;
int dp[100005];
vector<int> ans;
void dfs(int x, int p) {
  for (int i = 0; i < g[x].size(); i++) {
    int y = g[x][i].first;
    if (y == p) continue;
    dfs(y, x);
    int t = g[x][i].second;
    if (t == 1)
      dp[x] += dp[y];
    else {
      if (!dp[y]) {
        ans.push_back(y);
        dp[x]++;
      } else
        dp[x] += dp[y];
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y, t;
    scanf("%d%d%d", &x, &y, &t);
    g[x].push_back(make_pair(y, t));
    g[y].push_back(make_pair(x, t));
  }
  dfs(1, 0);
  cout << dp[1] << endl;
  for (int i = 0; i < ans.size(); i++) {
    if (i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
}
