#include <bits/stdc++.h>
using namespace std;
int n, x, y, z;
vector<int> Ans;
vector<vector<pair<int, int> > > adj(100023);
bool visit[100025];
int Prev[100035] = {0};
int Last;
inline void dfs(int node) {
  visit[node] = true;
  for (int i = 0; i < adj[node].size(); i++) {
    if (!visit[adj[node][i].first]) {
      dfs(adj[node][i].first);
      if (Prev[adj[node][i].first] == 1) Prev[node] = 1;
      if (adj[node][i].second == 2) {
        if (Prev[adj[node][i].first] == 0) {
          Ans.push_back(adj[node][i].first);
          Prev[node] = 1;
        }
      }
    }
  }
  return;
}
inline void ReadInput(void) {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y >> z;
    adj[x].push_back(pair<int, int>(y, z));
    adj[y].push_back(pair<int, int>(x, z));
  }
  for (int i = 0; i < n + 1; i++) visit[i] = false;
}
inline void Refresh(void) {}
inline void solve(void) {
  Last = -1;
  dfs(1);
  cout << Ans.size() << endl;
  for (int i = 0; i < Ans.size(); i++) cout << Ans[i] << " ";
}
int main(int argc, const char* argv[]) {
  ReadInput();
  solve();
  return 0;
}
