#include <bits/stdc++.h>
using namespace std;
int visited[100005];
vector<vector<pair<int, int> > > adjList(100005);
vector<int> vec;
int dfs(int x) {
  int sz = adjList[x].size();
  visited[x] = 1;
  int error = 0;
  for (int i = 0; i < sz; i++) {
    int child = adjList[x][i].first;
    if (!visited[child]) {
      int err = dfs(child);
      error += err;
      if (!err) {
        if (adjList[x][i].second == 2) {
          vec.push_back(child);
          error++;
        }
      }
    }
  }
  return error;
}
int main() {
  memset(visited, sizeof(visited), 0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int from, to, t;
    cin >> from >> to >> t;
    adjList[from].push_back(make_pair(to, t));
    adjList[to].push_back(make_pair(from, t));
  }
  dfs(1);
  int sz = vec.size();
  cout << sz << endl;
  for (int i = 0; i < sz; i++) cout << vec[i] << " ";
  return 0;
}
