400783: GYM100247 E Of Groups and Rights

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

Description

E. Of Groups and Rightstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Computer security specialist Alexey is setting up the access rights for the secret information about a certain programming contest. Security system is organized so that users are united into the groups numbered from 1 to n. Some groups can include the others. Each group can be directly included only in one other group, but one group can include several other groups. Group 1 includes all other groups directly or indirectly. If the group does not includes any other group, then it's actually a user. And vice versa, if the group is a user, it can't include any other groups.

For each group the access to the secret information can be allowed, denied or not set. If the access for the group is not set, it's inherited from the group that includes this one. If access is not set for that group too, it's inherited again and so on. If the access is not set even for the group 1, it's considered denied for the specified group.

Alexey has instructions about the groups, the rights for them and how the groups include each other. He wants to optimize his data structure in order that only the information about the allowed rights is stored, and for other groups it's considered not set. At the same time all users' access rights should be the same as followed from the initial instructions. Also Alexey wants new data structure to require less memory, so there should be minimal number of the permissions records. From all such structures he wants to select that one, for which the sum of the nesting levels for all stored groups is minimal.

Input

The first line contains an integer n (1 ≤ n ≤ 200000) — the number of groups.

Then the string of n characters «+», «-», «0» follows. Character «+» on the i-th position means the access is allowed for the i-th group, «-» — that the access is denied, and «0» — that it's not set.

Then n - 1 lines follow. Each of them contains two integers separated by a space: ai and bi (1 ≤ ai, bi ≤ n). Each of these records means that group ai includes the group bi.

Output

In the first line output the only integer m — minimal number of the groups, about which allowed access information should be stored.

In the second line output m integers separated by spaces — numbers of these groups in the ascending order.

ExamplesInput
10
+-+000++-+
1 2
1 5
1 9
2 6
2 8
5 4
5 10
9 3
9 7
Output
3
5 8 9

加入题单

上一题 下一题 算法标签: