#include <bits/stdc++.h>
using namespace std;
int sm[100005], tk[100005];
vector<pair<int, int>> v[100005];
bool vis[100005];
void dfs(int x) {
  sm[x] = tk[x];
  vis[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    int t = v[x][i].first, d = v[x][i].second;
    if (vis[t]) continue;
    if (d == 2) tk[t] = 1;
    dfs(t);
    sm[x] += sm[t];
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    v[x].push_back(make_pair(y, z));
    v[y].push_back(make_pair(x, z));
  }
  dfs(1);
  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (sm[i] == 1 && tk[i] == 1) ans.push_back(i);
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  return 0;
}
