#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;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Ci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ZWN0b3I8aW50PmRpc3QobisxLDFlOSk7CiAgdmVjdG9yPGludD5sZWFmczsKICB2ZWN0b3I8aW50PnBhcihuKzEsLTEpOwogIHEucHVzaCgxKTsKICBkaXN0WzFdPTA7CiAgd2hpbGUoIXEuZW1wdHkoKSl7CiAgICBpbnQgbm9kZSA9IHEuZnJvbnQoKTsKICAgIHEucG9wKCk7CiAgICBib29sIGxlYWYgPSAxOwogICAgZm9yKGF1dG8gW2NoLGNvXTogYWRqW25vZGVdKXsKICAgICAgaWYoZGlzdFtjaF0+ZGlzdFtub2RlXSsxKXsKICAgICAgICBkaXN0W2NoXT1kaXN0W25vZGVdKzE7CiAgICAgICAgbGVhZj0wOwogICAgICAgIHBhcltjaF09bm9kZTsKICAgICAgICBxLnB1c2goY2gpOwogICAgICB9CiAgICB9CiAgICBpZihsZWFmKWxlYWZzLnB1c2hfYmFjayhub2RlKTsKICB9CiAgZnVuY3Rpb248Ym9vbChpbnQpPnRyb3VibGU9WyZdKGludCBub2RlKXsKICAgIHdoaWxlKG5vZGUhPS0xKXsKICAgICAgaW50IHBhcmVudD1wYXJbbm9kZV07CiAgICAgIGZvcihhdXRvICZbY2gsY29dOmFkaltub2RlXSl7CiAgICAgICAgaWYoY2g9PXBhcmVudCAmJiBjbylyZXR1cm4gMTsKICAgICAgfQogICAgICBub2RlPXBhcmVudDsKICAgIH0KICAgIHJldHVybiAwOwogIH07CiAgdmVjdG9yPGludD5yZXM7CiAgZm9yKGF1dG8gbGVhZjpsZWFmcyl7CiAgICBpZih0cm91YmxlKGxlYWYpKXsKICAgICAgaW50IGN1ciA9IGxlYWY7CiAgICAgIHdoaWxlKGN1ciE9LTEpewogICAgICAgIGZvcihhdXRvICZbY2gsY29dOmFkaltjdXJdKXsKICAgICAgICAgIGlmKGNoPT1wYXJbY3VyXSljbz0wOwogICAgICAgIH0KICAgICAgICBpZihwYXJbY3VyXSE9LTEpewogICAgICAgICAgZm9yKGF1dG8gJltjaCxjb106YWRqW3BhcltjdXJdXSl7CiAgICAgICAgICAgIGlmKGNoPT1jdXIpY289MDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY3VyPXBhcltjdXJdOwogICAgICB9CiAgICAgIHJlcy5wdXNoX2JhY2sobGVhZik7CiAgICB9CiAgfQogIGNvdXQ8PHJlcy5zaXplKCk8PGVsOwogIGNvdXQ8PHJlczsKfQpEQVZJRHMgbWFpbigpIHsKICBmYXN0OwogIGludCB0PTE7CiAgLy8gY2luPj50OwogIHdoaWxlKHQtLSlzb2x2ZSgpOwogIHJldHVybiAwOwp9