#include <bits/stdc++.h>
using namespace std;
vector<int> ans_list;
map<pair<int, int>, bool> Bad;
int degree[100010], parent[100010];
bool vis[100010];
vector<int> adj[100010];
void dfs(int u) {
  vis[u] = true;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (!vis[v]) {
      parent[v] = u;
      degree[u]++;
      degree[v]++;
      dfs(v);
    }
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int u, v, ti;
    cin >> u >> v >> ti;
    adj[u].push_back(v);
    adj[v].push_back(u);
    if (u > v) swap(u, v);
    if (ti == 2) Bad[make_pair(u, v)] = true;
  }
  dfs(1);
  deque<int> leaves;
  for (int i = 2; i <= n; i++) {
    if (degree[i] == 1) {
      leaves.push_back(i);
    }
  }
  int ans = 0;
  while (leaves.size() != 0) {
    int u = leaves.front();
    leaves.pop_front();
    int m = min(u, parent[u]);
    int M = max(u, parent[u]);
    if (Bad.count(make_pair(m, M))) {
      ans++;
      ans_list.push_back(u);
    } else {
      int v = parent[u];
      degree[v]--;
      if (degree[v] == 1 && v != 1) leaves.push_front(v);
    }
  }
  cout << ans << "\n";
  for (int i = 0; i < ans_list.size(); i++) {
    cout << ans_list[i] << " ";
  }
  cout << "\n";
  return 0;
}
