#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
int read(){
int ans=0,f=1,c=getchar();
while(c<‘0‘||c>‘9‘){if(c==‘-‘) f=-1; c=getchar();}
while(c>=‘0‘&&c<=‘9‘){ans=ans*10+(c-‘0‘); c=getchar();}
return ans*f;
}
int T,f[200007];
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
set<int>tr[200007];
int vis[200007],cnt=1;
int ans[200007],ap;
int stk[200007],stp;
int a,b,h;
void clear(){
while(stp){
int x=stk[--stp];
tr[x].clear();
f[x]=x;
}
++cnt;
}
int main()
{
T=read();
for(int i=0;i<=200000;i++) f[i]=i;
for(int i=1;i<=T;i++){
a=read(); b=read(); h=read();
if(vis[a]!=cnt) stk[stp++]=a,vis[a]=cnt;
if(vis[b]!=cnt) stk[stp++]=b,vis[b]=cnt;
int p=find(a),q=find(b);
if(tr[p].size()<tr[q].size()) swap(p,q);
if(h==1){
if(p==q) continue;
if(tr[p].find(q)!=tr[p].end()){
clear();
ans[++ap]=i;
continue;
}
f[q]=p;
for(set<int>::iterator it=tr[q].begin();it!=tr[q].end();it++){
int z=*it;
tr[z].erase(q);
tr[z].insert(p);
tr[p].insert(z);
}
tr[q].clear();
}
else{
if(p==q){
clear();
ans[++ap]=i;
continue;
}
tr[p].insert(q);
tr[q].insert(p);
}
}
printf("%d\n",ap);
for(int i=1;i<=ap;i++) printf("%d\n",ans[i]-ans[i-1]);
return 0;
}