#include <bits/stdc++.h>
using namespace std;
int i, n, x, y, t, visited[100001];
map<int, bool> mark;
vector<pair<int, int> > adj[100001];
vector<int> ans;
void dfs(int x, int y) {
  visited[x] = 1;
  if (y == 2) {
    mark.clear();
    mark[x] = true;
  }
  for (int i = 0; i < adj[x].size(); i++)
    if (!visited[adj[x][i].first]) dfs(adj[x][i].first, adj[x][i].second);
  if (mark[x]) {
    ans.push_back(x);
    mark.clear();
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> x >> y >> t;
    adj[x].push_back({y, t});
    adj[y].push_back({x, t});
  }
  dfs(1, 0);
  cout << ans.size() << endl;
  for (i = 0; i < ans.size(); i++) cout << ans[i] << " ";
}
