CF369C.Valera and Elections

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

The city has nn districts and n1n-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 11 to nn , 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 nn candidates running the elections. Let's enumerate all candidates in some way by integers from 11 to nn , inclusive. If the candidate number ii will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the ii -th district to the district 11 , 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.

输入格式

The first line contains a single integer nn ( 2<=n<=1052<=n<=10^{5} ) — the number of districts in the city.

Then n1n-1 lines follow. Each line contains the description of a city road as three positive integers xix_{i} , yiy_{i} , tit_{i} ( 1<=xi,yi<=n1<=x_{i},y_{i}<=n , 1<=ti<=21<=t_{i}<=2 ) — the districts connected by the ii -th bidirectional road and the road type. If tit_{i} equals to one, then the ii -th road isn't the problem road; if tit_{i} equals to two, then the ii -th road is the problem road.

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

输出格式

In the first line print a single non-negative number kk — the minimum size of the required subset of candidates. Then on the second line print kk space-separated integers a1,a2,... aka_{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.

输入输出样例

  • 输入#1

    5
    1 2 2
    2 3 2
    3 4 2
    4 5 2
    

    输出#1

    1
    5 
    
  • 输入#2

    5
    1 2 1
    2 3 2
    2 4 1
    4 5 1
    

    输出#2

    1
    3 
    
  • 输入#3

    5
    1 2 2
    1 3 2
    1 4 2
    1 5 2
    

    输出#3

    4
    5 4 3 2 
    
首页