Rainbow Roads

Given a tree whose edges are colored, find every node v such that all simple paths starting at v have no two consecutive edges of the same color.

Hard8TreeDFSGraphImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given a tree with nn nodes, numbered from 1 to nn. Every edge has one of nn colors. A path in the tree is a rainbow path if every two adjacent edges on it have different colors. A node vv is good if every simple path that has vv as one of its endpoints is a rainbow path.

Find all the good nodes of the given tree.

A simple path is a path that repeats no vertex and no edge.

Input

The first line contains one integer nn (1n500001 \le n \le 50\,000).

Each of the next n1n - 1 lines contains three integers aia_i, bib_i, and cic_i separated by spaces (1ai,bi,cin1 \le a_i, b_i, c_i \le n, aibia_i \ne b_i). They describe an edge of color cic_i that connects node aia_i and node bib_i.

The given edges always form a tree.

Output

On the first line, print kk, the number of good nodes.

On each of the next kk lines, print the index of one good node, in increasing order.

Hint

The rainbow condition applies only to consecutive edges of a path. On a path v1,v2,v3,v4v_1, v_2, v_3, v_4 the edges (v1,v2)(v_1, v_2) and (v3,v4)(v_3, v_4) may share a color, because they are not adjacent. A path with at most one edge has no adjacent pair of edges, so it is always a rainbow path.