#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> ans;
int nxt[200005];
int to[200005];
int we[200005];
int head[100005];
int vis[100005];
int pos = 0;
void add(int a, int b, int w) {
  to[pos] = b;
  we[pos] = w;
  nxt[pos] = head[a];
  head[a] = pos++;
}
bool dfs(int p, int pd) {
  vis[p] = 1;
  if (pd == 2) {
    int flag = 0;
    for (int i = head[p]; i + 1; i = nxt[i]) {
      if (vis[to[i]]) continue;
      if (dfs(to[i], we[i])) {
        flag = 1;
        continue;
      }
    }
    if (!flag) ans.push_back(p);
    return true;
  } else {
    int flag = 0;
    for (int i = head[p]; i + 1; i = nxt[i]) {
      if (vis[to[i]]) continue;
      if (dfs(to[i], we[i])) {
        flag = 1;
      }
    }
    if (flag == 0)
      return false;
    else
      return true;
  }
}
int main() {
  memset(vis, 0, sizeof(vis));
  memset(head, -1, sizeof(head));
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w);
    add(v, u, w);
  }
  dfs(1, 1);
  int len = ans.size();
  cout << len << endl;
  for (int i = 0; i < len; i++) {
    cout << ans[i] << ' ';
  }
  return 0;
}
