#include <bits/stdc++.h>
using namespace std;
vector<int> edges[200000];
int visited[200000];
int n;
map<pair<int, int>, bool> bad;
vector<int> sol;
bool dfs(int u, bool b) {
  visited[u] = 1;
  bool r = false;
  for (int i = 0; i < (edges[u].size()); i++)
    if (!visited[edges[u][i]])
      r = (dfs(edges[u][i], bad[make_pair(u, edges[u][i])]) || r);
  if (b && !r) sol.push_back(u);
  return (r || b);
}
int main(void) {
  int a, b, c;
  cin >> n;
  for (int i = 0; i < (n - 1); i++) {
    cin >> a >> b >> c;
    a--;
    b--;
    c--;
    edges[a].push_back(b);
    edges[b].push_back(a);
    bad.insert(make_pair(make_pair(a, b), c));
    bad.insert(make_pair(make_pair(b, a), c));
  }
  dfs(0, false);
  cout << sol.size() << endl;
  for (int i = 0; i < (sol.size()); i++)
    cout << (sol[i] + 1) << (i + 1 == sol.size() ? '\n' : ' ');
  return 0;
}
