// Arup Guha
// 11/15/2017
// Solution to 2017 SER D1 and D2 Problem: Rainbow Roads

import java.util.*;

public class rainbow {

	public static int n;
	public static node[] g;

	public static void main(String[] args) {

		// Set up graph.
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		g = new node[n];
		for (int i=0; i<n; i++)
			g[i] = new node(i);

		// Add edges.
		for (int i=0; i<n-1; i++) {
			int u = stdin.nextInt()-1;
			int v = stdin.nextInt()-1;
			int c = stdin.nextInt();
			g[u].add(new edge(u,v,c));
			g[v].add(new edge(v,u,c));
		}

		// Now try to remove nodes by rooting a tree at each vertex.
		// Basically, if two subtrees from root i are the same color, all nodes
		// in those subtrees are bad. We remove edges once we explore them so that
		// there aren't run-time issues.
		for (int i=0; i<n; i++) {
			kill(i);
		}

		// Count good nodes.
		int res = 0;
		for (int i=0; i<n; i++)
			if (g[i].good) res++;

		// Print result.
		System.out.println(res);
		for (int i=0; i<n; i++)
			if (g[i].good)
				System.out.println(i+1);
	}


	public static void kill(int u) {

		LinkedList<edge> list = g[u].eList;

		int size = list.size();
		// Go through each edge.
		for (int i=0; i<size; i++) {

			edge e = list.poll();

			// Kill this subtree.
			if (g[u].colorFreq.get(e.color) > 1)
				dfs(e.v, e.u);

			// Put back since we want this still in the graph.
			else
				list.offer(e);
		}
	}

	// Kill all nodes rooted at u with parent par.
	public static void dfs(int u, int par) {

		LinkedList<edge> list = g[u].eList;
		g[u].good = false;
		int size = list.size();

		// Go through each edge, delete it if we recurse on it.
		for (int i=0; i<size; i++) {
			edge e = list.poll();
			if (e.v != par)
				dfs(e.v, e.u);
			else
				list.offer(e);
		}
	}
}

class edge {

	public int u;
	public int v;
	public int color;

	public edge(int myu, int myv, int myc) {
		u = myu;
		v = myv;
		color = myc;
	}
}

class node {

	public int id;
	public LinkedList<edge> eList;
	public HashMap<Integer,Integer> colorFreq;
	public boolean good;

	public node(int myid) {
		id = myid;
		eList = new LinkedList<edge>();
		colorFreq = new HashMap<Integer,Integer>();
		good = true;
	}

	// Assumes e goes from this node to another...
	public void add(edge e) {
		eList.offer(e);
		if (colorFreq.containsKey(e.color))
			colorFreq.put(e.color, colorFreq.get(e.color)+1);
		else
			colorFreq.put(e.color, 1);
	}
}