#include <bits/stdc++.h>
using namespace std;
void dfs(int par, int u, bool b, vector<int>& parent, vector<bool>& bad,
         vector<vector<pair<int, bool>>>& adj) {
  if (parent[u] != -1) return;
  parent[u] = par;
  bad[u] = b;
  for (int i = 0; i < adj[u].size(); i++)
    dfs(u, adj[u][i].first, adj[u][i].second, parent, bad, adj);
}
bool mark(int u, vector<bool>& bad, vector<vector<pair<int, bool>>>& adj,
          vector<bool>& done) {
  if (done[u]) return 0;
  done[u] = 1;
  bool e = 0;
  for (int i = 0; i < adj[u].size(); i++)
    e = mark(adj[u][i].first, bad, adj, done) || e;
  return bad[u] = bad[u] || e;
}
vector<int> ep;
void cnt(int u, vector<bool>& bad, vector<vector<pair<int, bool>>>& adj,
         vector<bool>& done) {
  if (done[u] || !bad[u]) return;
  done[u] = 1;
  int c = 0;
  for (int i = 0; i < adj[u].size(); i++)
    if (!done[adj[u][i].first] && bad[adj[u][i].first]) c++;
  if (!c) {
    ep.push_back(u);
    return;
  }
  for (int i = 0; i < adj[u].size(); i++) cnt(adj[u][i].first, bad, adj, done);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<vector<pair<int, bool>>> adj(n);
  vector<bool> problem(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y, t;
    cin >> x >> y >> t;
    x--;
    y--;
    adj[x].push_back({y, t - 1});
    adj[y].push_back({x, t - 1});
  }
  adj[0].push_back({0, 0});
  vector<int> parent(n, -1);
  vector<bool> bad(n);
  parent[0] = 0;
  for (int i = 0; i < adj[0].size(); i++)
    dfs(0, adj[0][i].first, adj[0][i].second, parent, bad, adj);
  vector<bool> done(n);
  mark(0, bad, adj, done);
  fill(done.begin(), done.end(), 0);
  cnt(0, bad, adj, done);
  cout << ep.size() << "\n";
  for (int i = 0; i < ep.size(); i++)
    cout << ep[i] + 1 << " \n"[i == ep.size() - 1];
}
