#include <bits/stdc++.h>
using namespace std;
long long int visit[500005], level[500005];
vector<long long int> v[500005], v2;
map<pair<long long int, long long int>, long long int> m;
int dfs(long long int cur, long long int par) {
  visit[cur] = 1;
  long long int c = 0;
  for (auto x : v[cur])
    if (!visit[x]) c += dfs(x, cur);
  if (c == 0 && m[{cur, par}] == 2) {
    c++;
    v2.push_back(cur);
  }
  return c;
}
int main() {
  long long int n, m_, x, y, t, i;
  cin >> n;
  m_ = n - 1;
  while (m_--) {
    cin >> x >> y >> t;
    v[x].push_back(y);
    v[y].push_back(x);
    m[{x, y}] = t;
    m[{y, x}] = t;
  }
  dfs(1, -1);
  cout << v2.size() << "\n";
  for (auto x : v2) cout << x << " ";
  return 0;
}
