# class node():
#     def __init__(self,id, *args, **kwargs):
#         self.id=id
#         self.child=[]
#         self.state=[]


#     def add_child(self,n,state):
#         self.child+=[n]
#         self.state+=[state]

n=int(input())
dist=[None]*n
node=list(range(n))
for i in range(n):
    dist[i]=[-1]*n
for i in range(n-1):
    u,v,c=map(int,input().split(" "))
    dist[u-1][v-1]=c-1
    dist[v-1][u-1]=c-1
def search(id,parent,state):
    # print("search",id)
    res=state
    for i in range(n):
        if i!=parent:
            # print(id,i,"dist",dist[id][i])
            if dist[id][i]>=0:
                res+=search(i,id,dist[id][i])
    if res==0:
        if id in node:
            node.remove(id)
        for i in range(n):
            dist[id][i]=-1
            dist[i][id]=-1
    return res
final=[]

def count_leaf(id,parent):
    is_leaf=1
    res=0
    for i in range(n):
        if i!=parent:
            # print(id,i,"dist",dist[id][i])
            if dist[id][i]>=0:
                # print(id,i,"dist",dist[id][i])
                is_leaf=0
                res+=count_leaf(i,id)
    if is_leaf==1:
        global final
        final+=[id]
    return res+is_leaf
count_leaf(0,0)
search(0,0,0)
final=[x+1 for x in final]
print(len(final))
print(" ".join(map(str,final)))

