#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
vector<pair<long long, long long> > edge[N];
vector<int> ans;
int dp[N], flag[N];
void dfs(int t, int fa) {
  dp[t] = flag[t];
  for (pair<long long, long long> p : edge[t]) {
    if (p.first != fa) {
      dfs(p.first, t);
      dp[t] += dp[p.first];
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0, x, y, t; i < n - 1; i++) {
    scanf("%d %d %d", &x, &y, &t);
    edge[x].push_back(pair<long long, long long>(y, t)),
        edge[y].push_back(pair<long long, long long>(x, t));
    if (t == 2) flag[x] = flag[y] = 1;
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++)
    if (flag[i] && dp[i] == 1) ans.push_back(i);
  printf("%d\n", (int)ans.size());
  for (int i = 0, size = ans.size(); i < size; i++)
    printf("%d%s", ans[i], i == size - 1 ? "\n" : " ");
  return 0;
}
