#include <bits/stdc++.h>
using namespace std;
vector<pair<int, bool> > arr[100005];
vector<int> v1;
bool brr[100005];
bool visited[100005];
void dfs(int u) {
  visited[u] = true;
  for (int i = 0; i < arr[u].size(); i++) {
    if (visited[arr[u][i].first] == false) {
      dfs(arr[u][i].first);
      {
        if (brr[arr[u][i].first] == false && arr[u][i].second == true) {
          v1.push_back(arr[u][i].first);
          brr[u] = true;
        }
        if (brr[arr[u][i].first] == true) brr[u] = true;
      }
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int u, v, w;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v >> w;
    if (w == 2) {
      arr[u].push_back(make_pair(v, true));
      arr[v].push_back(make_pair(u, true));
    } else {
      arr[u].push_back(make_pair(v, false));
      arr[v].push_back(make_pair(u, false));
    }
  }
  dfs(1);
  cout << v1.size() << endl;
  for (int i = 0; i < v1.size(); i++) cout << v1[i] << " ";
  cout << endl;
}
