#include <bits/stdc++.h>
const int MAXN = 100005;
const long long inf = 1e18;
using namespace std;
int n, dp[MAXN];
bool w[MAXN];
vector<int> adj[MAXN];
void dfs(int v, int par) {
  dp[v] = 0;
  if (w[v]) dp[v] += 1;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i];
    if (u == par) continue;
    dfs(u, v);
    dp[v] += dp[u];
  }
}
void solve() {
  cin >> n;
  int x, y, z;
  memset(w, false, sizeof w);
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> z;
    if (z == 2) w[x] = w[y] = true;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0);
  int count = 0;
  for (int i = 1; i < n + 1; i++) {
    if (dp[i] == 1) count++;
  }
  cout << count << '\n';
  for (int i = 1; i < n + 1; i++) {
    if (dp[i] == 1) cout << i << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
