#include <bits/stdc++.h>
using namespace std;
static const double PI = 2 * acos(0);
vector<int> dists, prevs, btohere;
vector<bool> broken;
vector<vector<pair<int, int> > > edges;
int dfs1(int loc) {
  for (int i = 0; i < edges[loc].size(); i++) {
    int next = edges[loc][i].first;
    bool broke = edges[loc][i].second;
    if (prevs[next] == -1) {
      prevs[next] = loc;
      dists[next] = dists[loc] + 1;
      btohere[next] = broke;
      btohere[loc] += dfs1(next);
    }
  }
  return btohere[loc];
}
vector<int> answers;
vector<bool> visited;
void dfs2(int loc) {
  visited[loc] = true;
  bool used = false;
  for (int i = 0; i < edges[loc].size(); i++) {
    int next = edges[loc][i].first;
    if (visited[next] == false && btohere[next] > 0) {
      dfs2(next);
      used = true;
    }
  }
  if (btohere[loc] == 1 && used == 0) {
    answers.push_back(loc);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  dists.assign(N, 0);
  btohere.assign(N, 0);
  prevs.assign(N, -1);
  broken.assign(N, false);
  edges.assign(N, vector<pair<int, int> >());
  for (int i = 0; i < (int)(N - 1); i++) {
    int x, y, b;
    cin >> x >> y >> b;
    x--, y--;
    bool bad = b == 2;
    edges[x].push_back({y, bad});
    edges[y].push_back({x, bad});
  }
  prevs[0] = 0;
  dfs1(0);
  visited.assign(N, false);
  dfs2(0);
  cout << answers.size() << endl;
  for (int i = 0; i < (int)(answers.size()); i++) {
    cout << answers[i] + 1 << " ";
  }
  cout << endl;
  visited.assign(N, false);
  return 0;
}
