Under construction

Still being built. Things may change

Turning Off the Tree Lights

Time limit2sMemory limit1024 MB

Summary
Bob walks on a tree, flipping the bulb at each vertex he leaves, and must turn all bulbs off in at most 4N moves starting from vertex a.
Level

Hard8 of 10

Topics
Tree, DFS, Implementation, Greedy
Solved
No attempts yet

Problem

NN vertices form a tree. A tree is a connected graph whose edges have no direction, and the shortest path between any two vertices is unique. Each vertex has a bulb and a switch. A bulb is either on or off. Pressing the switch of a vertex flips the state of that vertex's bulb. A bulb that is on turns off, and a bulb that is off turns on.

Bob is a sloth living on this tree. Bob starts at vertex aa. He wants to make all bulbs off by repeating the following procedure zero or more times.

  • Suppose Bob is at vertex vv. He chooses a vertex uu adjacent to vv, presses the switch at vv, and moves to uu.

Help Bob find a way to make all bulbs off using the procedure at most 4N4N times. The problem conditions guarantee that such a way always exists.

Input

The first line contains the number of vertices NN and the vertex aa where Bob starts, separated by a space. (2≤N≤100 0002 \le N \le 100\,000; 1≤a≤N1 \le a \le N)

The second line contains a string SS of length nn that describes the bulbs. If the bulb at vertex ii is on, the ii-th character is \tt{'1'}. Otherwise, the ii-th character is \tt{'0'}.

From the third line onward, each of the N−1N-1 lines contains two vertices xix_i and yiy_i that are connected by an edge, separated by a space. (1≤xi<yi≤N1 \le x_i < y_i \le N)

The given graph is guaranteed to be a valid tree.

Output

On the first line, print the number kk of procedures to carry out, where 0≤k≤4N0 \le k \le 4N.

On the second line, print kk integers u1,u2,⋯ ,uku_1, u_2, \cdots, u_k, separated by spaces, that give the vertex chosen in each procedure. Vertex u1u_1 must be adjacent to aa, and for every ii with 2≤i≤k2 \le i \le k, vertex uiu_i must be adjacent to ui−1u_{i-1}.

If there are several ways to make all bulbs off, print any one of them. The number of procedures does not need to be minimal.

Hint

The steps that Bob follows in the example, and the resulting bulb states, are as follows.

  1. Bob moves to u=3u=3, and the bulb at v=4v=4 turns off.
  2. Bob moves to u=2u=2, and the bulb at v=3v=3 turns off.
  3. Bob moves to u=1u=1, and the bulb at v=2v=2 turns on.
  4. Bob moves to u=2u=2, and the bulb at v=1v=1 turns off.
  5. Bob moves to u=3u=3, and the bulb at v=2v=2 turns off.
  6. Bob moves to u=5u=5, and the bulb at v=3v=3 turns on.
  7. Bob moves to u=3u=3, and the bulb at v=5v=5 turns on.
  8. Bob moves to u=5u=5, and the bulb at v=3v=3 turns off.
  9. Bob moves to u=3u=3, and the bulb at v=5v=5 turns off.
  10. Bob moves to u=6u=6, and the bulb at v=3v=3 turns on.
  11. Bob moves to u=3u=3, and the bulb at v=6v=6 turns off.
  12. Bob moves to u=4u=4, and the bulb at v=3v=3 turns off.

A total of 12 procedures are carried out, and all bulbs are off when the procedure ends.

Examples1

  1. Example 1

    Input
    6 4
    101101
    1 2
    2 3
    3 4
    3 5
    3 6
    
    Expected output
    12
    3 2 1 2 3 5 3 5 3 6 3 4