#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> cn(long long int n, long long int m) {
  return vector<vector<long long int>>(n, vector<long long int>(m));
}
bool compare(char &s1, char &s2) { return s1 > s2; }
bool sortmahstyle(const pair<long long int, long long int> &a,
                  const pair<long long int, long long int> &b) {
  if (a.first < b.first) return true;
  if (a.first == b.first && a.second != b.second) return true;
  return false;
}
long long int const mod = 1e9 + 7;
long long int const inf = 1e18;
long long int const maxn = 1e6 + 1;
vector<pair<long long int, long long int>> adj[maxn];
vector<long long int> all, ans;
long long int vis[maxn];
bool dfs(long long int x, long long int par) {
  long long int work = 0;
  for (auto ch : adj[x]) {
    if (ch.first != par) {
      bool status = dfs(ch.first, x);
      if (status)
        work = 1;
      else {
        if (ch.second == 2) ans.push_back(ch.first), work = 1;
      }
    }
  }
  return work;
}
void solve() {
  long long int n;
  cin >> n;
  for (long long int i = 1; i < n; i++) {
    long long int u, v, t;
    cin >> u >> v >> t;
    adj[u].push_back({v, t});
    adj[v].push_back({u, t});
  }
  dfs(1, -1);
  cout << ans.size() << "\n";
  for (auto e : ans) cout << e << " ";
  cout << "\n";
  ;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  t = 1;
  for (long long int testcases = 0; testcases < t; testcases++) {
    solve();
  }
  return 0;
}
