301947: CF369C. Valera and Elections

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Valera and Elections

题意翻译

## 题目描述 Z国共有$N$个城市,标号$1..N$.其中1号为首都. 一共有$N-1$条双向道路,连通了$N$个城市.其中有些路年久失修了. 现在可以选择一些城市,被选择的城市到首都之间的道路都将被重新修整. 请选择个数最少的若干城市,使得所有损坏的道路都能得到修复. ## 输入 第一行,整数$N$.$(1≤N≤2*10^5 )$ 下面N-1行,每行描述一条道路.整数u,v,x,表示城市u和v之间有道路, x=1表示正常, x=2表示损坏. ## 输出 第一行,整数k,表示你选择的城市个数. 第二行,k个整数,以空格分隔,表示你选择的城市标号.

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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.

输入输出样例

输入样例 #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 

Input

题意翻译

## 题目描述 Z国共有$N$个城市,标号$1..N$.其中1号为首都. 一共有$N-1$条双向道路,连通了$N$个城市.其中有些路年久失修了. 现在可以选择一些城市,被选择的城市到首都之间的道路都将被重新修整. 请选择个数最少的若干城市,使得所有损坏的道路都能得到修复. ## 输入 第一行,整数$N$.$(1≤N≤2*10^5 )$ 下面N-1行,每行描述一条道路.整数u,v,x,表示城市u和v之间有道路, x=1表示正常, x=2表示损坏. ## 输出 第一行,整数k,表示你选择的城市个数. 第二行,k个整数,以空格分隔,表示你选择的城市标号.

加入题单

算法标签: