#include <bits/stdc++.h>
using namespace std;
int n, cnt[100005];
vector<pair<int, int> > g[100005];
vector<int> ans;
void DFS(int u, int p) {
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (v != p) {
      if (g[u][i].second) cnt[u]++, cnt[v]++;
      DFS(v, u);
      cnt[u] += cnt[v];
    }
  }
  if (cnt[u] == 1) ans.push_back(u);
}
bool cmp(pair<int, int> x, pair<int, int> y) { return x.second > y.second; }
int main() {
  cin >> n;
  int u, v, w;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v >> w;
    g[u].push_back(pair<int, int>(v, w - 1));
    g[v].push_back(pair<int, int>(u, w - 1));
  }
  for (int i = 0; i < n; i++) sort(g[i].begin(), g[i].end(), cmp);
  DFS(1, 1);
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
}
