Codeforces Round 216 (Div. 2)
C
Valera and Elections
Codeforces
1600
原题
← BD →
翻译中…

The city Valera lives in is going to hold elections to the city Parliament.

翻译中…

The city has $*n*$ districts and $*n* - 1$ bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from $1$ to $*n*$, inclusive. Furthermore, for each road the residents decided if it is the problem road or not. A problem road is a road that needs to be repaired.

翻译中…

There are $*n*$ candidates running the elections. Let's enumerate all candidates in some way by integers from $1$ to $*n*$, inclusive. If the candidate number $*i*$ will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the $*i*$-th district to the district $1$, where the city Parliament is located.

翻译中…

Help Valera and determine the subset of candidates such that if all candidates from the subset will be elected to the city Parliament, all problem roads in the city will be repaired. If there are several such subsets, you should choose the subset consisting of the minimum number of candidates.

翻译中…

Input

翻译中…

The first line contains a single integer $*n*$ ($2 ≤ *n* ≤ 10^{5}$) — the number of districts in the city.

翻译中…

Then $*n* - 1$ lines follow. Each line contains the description of a city road as three positive integers $*x*_{*i*}$, $*y*_{*i*}$, $*t*_{*i*}$ ($1 ≤ *x*_{*i*}, *y*_{*i*} ≤ *n*$, $1 ≤ *t*_{*i*} ≤ 2$) — the districts connected by the $*i*$-th bidirectional road and the road type. If $*t*_{*i*}$ equals to one, then the $*i*$-th road isn't the problem road; if $*t*_{*i*}$ equals to two, then the $*i*$-th road is the problem road.

翻译中…

It's guaranteed that the graph structure of the city is a tree.

翻译中…

Output

翻译中…

In the first line print a single non-negative number $*k*$ — the minimum size of the required subset of candidates. Then on the second line print $*k*$ space-separated integers $*a*_{1}, *a*_{2}, ... *a*_{*k*}$ — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print any of them.

翻译中…

样例

Input #1
5
1 2 2
2 3 2
3 4 2
4 5 2
Output #1
1
5
InputCopy OutputCopy
Input #2
5
1 2 1
2 3 2
2 4 1
4 5 1
Output #2
1
3
InputCopy OutputCopy
Input #3
5
1 2 2
1 3 2
1 4 2
1 5 2
Output #3
4
5 4 3 2
InputCopy OutputCopy
题目信息
题号
369C
时间限制
1 s
内存限制
256 MB
标签
DFS 及类似
图论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。