import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Solution to Star Arrangements
 * 
 * @author vanb
 */
public class rainbow_vanb
{
    private static Scanner sc;
    private static PrintStream ps;
    
    private class Road
    {
        public Intersection destination;
        public int color;
        
        public Road( Intersection destination, int color )
        {
            this.destination = destination;
            this.color = color;
        }
    }
    
    private int count;
    
    private class Intersection
    {
        public boolean eliminated = false;
        public List<Road> roads = new ArrayList<Road>(); 
        public int index;
        
        public Intersection( int index )
        {
            this.index = index;
        }
        
        public void eliminate( Intersection from )
        {
            //System.err.println( "Eliminating " + index );
            if( !eliminated )
            {
                eliminated = true;
                --count;
            }
                
            for( Road road : roads ) if( road.destination!=from ) road.destination.eliminate( this );
        }
    }
    
    private void doit()
    {
        int n = sc.nextInt();
        
        Intersection intersections[] = new Intersection[n];
        for( int i=0; i<n; i++ ) intersections[i] = new Intersection( i+1 );
        for( int i=0; i<n-1; i++ )
        {
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            int c = sc.nextInt();
            
            intersections[a].roads.add( new Road( intersections[b], c ) );
            intersections[b].roads.add( new Road( intersections[a], c ) );
        }
        
        count = n;
        
        Intersection colors[] = new Intersection[n];
        for( Intersection intersection : intersections ) 
        {
            Arrays.fill( colors, null );
            for( Road road : intersection.roads )
            {
                int color = road.color;
                if( colors[color]==null )
                {
                    colors[color] = road.destination;
                }
                else
                {
                    colors[color].eliminate( intersection );
                    road.destination.eliminate( intersection );
                }
            }
        }
        
        ps.println( count );
        for( Intersection intersection : intersections ) if( !intersection.eliminated )
        {
            ps.println( intersection.index );
        }
    }
        
    public static void main( String[] args ) throws Exception
    {
        sc = new Scanner( System.in );
        ps = System.out;
        
        new rainbow_vanb().doit();
    }

}
