#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 123;
const int mod = 1e9 + 7;
const int INF = 1e9 + 1;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, dp[N];
bool used[N], w[N];
vector<int> g[N];
vector<int> ans;
void go(int v = 1, int p = -1) {
  dp[v] = w[v];
  used[v] = 1;
  for (auto i : g[v])
    if (!used[i] && i != p) {
      go(i, v);
      dp[v] += dp[i];
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int m = n - 1;
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back(b);
    g[b].push_back(a);
    if (c > 1) w[a] = w[b] = 1;
  }
  go();
  for (int i = 1; i <= n; i++)
    if (dp[i] == 1) ans.push_back(i);
  cout << ans.size() << "\n";
  for (auto i : ans) cout << i << ' ';
  return 0;
}
