#include <bits/stdc++.h>
const int mod = ((1E9) + 7);
const int intmax = ((1E9) + 7);
using namespace std;
vector<pair<int, int> > adj[100005];
vector<int> ans;
int status[100005];
void dfs1(int v, int par, int st) {
  status[v] = st;
  for (auto u : adj[v]) {
    if (u.first != par) {
      dfs1(u.first, v, u.second);
    }
  }
}
bool dfs2(int v, int par) {
  int f = 0;
  bool res = false;
  for (auto u : adj[v]) {
    if (u.first != par) {
      f = 1;
      res |= dfs2(u.first, v);
    }
  }
  if (!f) {
    if (status[v] == 2) {
      ans.push_back(v);
      return true;
    }
    return false;
  }
  if (!res) {
    if (status[v] == 2) {
      ans.push_back(v);
      return true;
    }
    return false;
  }
  return true;
}
int main() {
  int test, a, b, c, n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &a);
    scanf("%d", &b);
    ;
    scanf("%d", &c);
    adj[a].push_back({b, c});
    adj[b].push_back({a, c});
  }
  status[1] = 1;
  dfs1(1, -1, 0);
  dfs2(1, -1);
  cout << ans.size() << endl;
  for (auto u : ans) cout << u << " ";
  return 0;
}
