#include <bits/stdc++.h>
using namespace std;
int V;
vector<int> res;
vector<vector<pair<int, int> > > adjList;
const int MAX = 1e5 + 10;
int cnt[MAX];
bool visited[MAX];
void dfs(int cur) {
  visited[cur] = true;
  for (int i = 0; i < (int)adjList[cur].size(); ++i) {
    int v = adjList[cur][i].first;
    if (!visited[v]) {
      dfs(v);
      cnt[v] += (adjList[cur][i].second == 2);
      cnt[cur] += cnt[v];
    }
  }
}
void dfs2(int cur) {
  visited[cur] = true;
  if (!cnt[cur]) return;
  bool entered = 0;
  for (int i = 0; i < (int)adjList[cur].size(); ++i) {
    int v = adjList[cur][i].first;
    if (!visited[v] && cnt[v]) {
      dfs2(v);
      entered = 1;
    }
  }
  if (!entered) res.push_back(cur + 1);
}
int main() {
  cin >> V;
  adjList.assign(V, vector<pair<int, int> >());
  for (int i = 0; i < V - 1; ++i) {
    int u, v, x;
    cin >> u >> v >> x;
    u--;
    v--;
    adjList[u].push_back(make_pair(v, x));
    adjList[v].push_back(make_pair(u, x));
  }
  dfs(0);
  memset(visited, false, sizeof(visited));
  dfs2(0);
  cout << res.size() << "\n";
  for (int i = 0; i < (int)res.size(); ++i)
    if (i == 0)
      cout << res[i];
    else
      cout << " " << res[i];
  cout << "\n";
  return 0;
}
