#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define el '\n'
#define all(v) v.begin() , v.end() 
#define ull unsigned long long 
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define loop(n) for(int i=0; i<n; i++)
#define int ll
#define DAVIDs signed
const int dx[]={1,-1, 0, 0, 1, 1,-1,-1};
const int dy[]={0, 0, 1,-1, 1,-1,-1, 1};
const int N = 1e5+5;
const int MOD = 1e9 + 7;
#define mod %MOD
istream& operator>>(istream& in, vector<int>& v){
  for(auto& it: v) in >> it;
  return in;
}
ostream& operator<<(ostream& out, vector<int>&v){
  for(auto& it: v) out << it << ' ';
  return out ;
}

void solve(){
  int n; cin>>n;
  vector<pair<int,int>>adj[n+1];
  for(int i=1; i<n; i++){
    int a,b,c; cin>>a>>b>>c;
    adj[a].push_back({b,c-1});
    adj[b].push_back({a,c-1});
  }
  queue<int>q;
  vector<int>dist(n+1,1e9);
  vector<int>leafs;
  vector<int>par(n+1,-1);
  q.push(1);
  dist[1]=0;
  while(!q.empty()){
    int node = q.front();
    q.pop();
    bool leaf = 1;
    for(auto [ch,co]: adj[node]){
      if(dist[ch]>dist[node]+1){
        dist[ch]=dist[node]+1;
        leaf=0;
        par[ch]=node;
        q.push(ch);
      }
    }
    if(leaf)leafs.push_back(node);
  }
  function<bool(int)>trouble=[&](int node){
    while(node!=-1){
      int parent=par[node];
      for(auto &[ch,co]:adj[node]){
        if(ch==parent && co)return 1;
      }
      node=parent;
    }
    return 0;
  };
  vector<int>res;
  for(auto leaf:leafs){
    if(trouble(leaf)){
      int cur = leaf;
      while(cur!=-1){
        for(auto &[ch,co]:adj[cur]){
          if(ch==par[cur])co=0;
        }
        if(par[cur]!=-1){
          for(auto &[ch,co]:adj[par[cur]]){
            if(ch==cur)co=0;
          }
        }
        cur=par[cur];
      }
      res.push_back(leaf);
    }
  }
  cout<<res.size()<<el;
  cout<<res;
}
DAVIDs main() {
  fast;
  int t=1;
  // cin>>t;
  while(t--)solve();
  return 0;
}