#include <bits/stdc++.h>
using namespace std;
long long n, i, j, sz = 1e6 + 2;
set<long long> ans;
vector<long long> v[1000000];
bool visit[1000000];
pair<long long, long long> dfs(long long x, long long cnt) {
  vector<pair<long long, long long>> v2;
  visit[x] = true;
  if (v[x].size() / 2 == 1 and visit[v[x][0]]) {
    if (cnt)
      return {1, x};
    else
      return {0, x};
  }
  for (long long i = 0; i < v[x].size(); i += 2) {
    if (!visit[v[x][i]]) v2.push_back(dfs(v[x][i], v[x][i + 1] == 2));
  }
  sort(v2.begin(), v2.end(), greater<pair<long long, long long>>());
  if (v2[0].first == 0) {
    if (cnt == 1)
      return {1, v2[0].second};
    else
      return {0LL, v2[0].second};
  }
  for (long long i = 0; i < v2.size(); i++) {
    if (v2[i].first == 0) break;
    ans.insert(v2[i].second);
  }
  return v2[0];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  long long x, y, z;
  for (i = 1; i <= n - 1; i++)
    cin >> x >> y >> z, v[x].push_back(y), v[y].push_back(x), v[x].push_back(z),
        v[y].push_back(z);
  dfs(1, 0LL);
  cout << ans.size() << endl;
  for (auto i : ans) cout << i << " ";
}
