#include <bits/stdc++.h>
using namespace std;
int dp[123456];
map<pair<int, int>, int> mp;
vector<int> v[123456];
bool vis[123456];
bool vist[123456];
vector<int> ans;
void dfs(int node) {
  vis[node] = true;
  int z = v[node].size();
  int nd;
  dp[node] = 0;
  for (int i = 0; i < z; i++) {
    nd = v[node][i];
    if (vis[nd]) continue;
    dfs(nd);
    dp[node] += dp[nd];
    if (mp[{node, nd}] == 2) dp[node]++;
  }
  return;
}
void dfs2(int node, int par) {
  vist[node] = true;
  int z = v[node].size();
  int nd;
  if (dp[node] == 0 && dp[par] > 0 && mp[{node, par}] == 2) ans.push_back(node);
  for (int i = 0; i < z; i++) {
    nd = v[node][i];
    ;
    if (nd == par) continue;
    dfs2(nd, node);
  }
}
int main() {
  int n;
  cin >> n;
  int x, y, t;
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y >> t;
    v[x].push_back(y);
    v[y].push_back(x);
    mp[{x, y}] = mp[{y, x}] = t;
  }
  dfs(1);
  dfs2(1, 0);
  int z = ans.size();
  cout << z << endl;
  for (int i = 0; i < z; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
