#include <bits/stdc++.h>
using namespace std;
const int64_t mod = 1e9 + 7;
const int N = 2e6 + 1;
int n;
bool mark[N];
vector<pair<int, int> > adj[N];
void dfs(int v, int p, int far) {
  for (auto vv : adj[v])
    if (vv.first != p) {
      if (vv.second == 2) {
        mark[far] = 0;
        mark[vv.first] = 1;
        dfs(vv.first, v, vv.first);
      } else
        dfs(vv.first, v, far);
    }
}
int main() {
  int u, v, is;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> u >> v >> is;
    adj[u].push_back({v, is});
    adj[v].push_back({u, is});
  }
  mark[1] = 1;
  dfs(1, -1, 1);
  int cnt = 0;
  vector<int> res;
  for (int i = 2; i <= n; i++)
    if (mark[i]) res.push_back(i);
  cout << res.size() << "\n";
  for (auto k : res) cout << k << " ";
  return 0;
}
