#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > V[(int)2e5 + 100];
int visited[(int)2e5 + 100];
int ansCnt = 0;
int ans[(int)2e5 + 100];
bool selected[(int)2e5 + 100];
void dfs(int v) {
  visited[v] = 1;
  bool ifSelected = false;
  for (int i = 0; i < V[v].size(); i++) {
    if (visited[V[v][i].first] == 0) {
      dfs(V[v][i].first);
      if (selected[V[v][i].first] == true) {
        ifSelected = true;
      } else if (selected[V[v][i].first] == false && V[v][i].second == 2) {
        ifSelected = true;
        ans[ansCnt++] = V[v][i].first;
      }
    }
  }
  selected[v] = ifSelected;
}
int main() {
  int n, city1, city2, type;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &city1);
    scanf("%d", &city2);
    scanf("%d", &type);
    V[city1].push_back(make_pair(city2, type));
    V[city2].push_back(make_pair(city1, type));
  }
  dfs(1);
  cout << ansCnt << endl;
  for (int i = 0; i < ansCnt; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
