#include <bits/stdc++.h>
using namespace std;
struct Rd {
  int y, t;
  Rd(int Y, int T) : y(Y), t(T) {}
};
vector<int> candi;
int dfs(int node, bool needCover, vector<bool>& visited,
        const vector<vector<Rd>>& edge) {
  visited[node] = true;
  int subCovers = 0;
  for (int i = 0; i < edge[node].size(); ++i) {
    if (!visited[edge[node][i].y]) {
      subCovers += dfs(edge[node][i].y, edge[node][i].t == 2, visited, edge);
    }
  }
  if (subCovers == 0 && needCover) {
    candi.push_back(node);
    return 1;
  } else {
    return subCovers;
  }
}
int main() {
  int n, x, y, t;
  scanf("%d", &n);
  vector<vector<Rd>> edge(n + 1);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d%d", &x, &y, &t);
    edge[x].emplace_back(Rd(y, t));
    edge[y].emplace_back(Rd(x, t));
  }
  vector<bool> visited(n + 1, false);
  int ret = dfs(1, false, visited, edge);
  printf("%d\n", ret);
  if (ret > 0) {
    for (int i = 0; i < ret - 1; ++i) {
      printf("%d ", candi[i]);
    }
    printf("%d\n", candi.back());
  }
  return 0;
}
