#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[4 * 100000];
vector<int> ans;
bool visited[4 * 100000];
void dfs(int u, int prev) {
  for (int i = 0; i < v[u].size(); i++) {
    int v1 = v[u][i].first;
    int flag = v[u][i].second;
    if (v1 == prev) continue;
    dfs(v1, u);
    int f = 0;
    if (flag == 2) {
      if (!visited[v1]) {
        ans.push_back(v1);
        visited[v1] = 1;
      }
    }
    visited[u] = visited[u] || visited[v1];
  }
}
int main() {
  int n, x, y, f;
  cin >> n;
  int p = n;
  n--;
  while (n--) {
    cin >> x >> y >> f;
    v[x].push_back(make_pair(y, f));
    v[y].push_back(make_pair(x, f));
  }
  dfs(1, -1);
  cout << ans.size() << endl;
  sort(ans.begin(), ans.end(), greater<int>());
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
