#P8119. Rainbow Dragon Cave Tour
Rainbow Dragon Cave Tour
Rainbow Dragon Cave Tour
In the problem, the interior of Honglong Cave is abstracted as an undirected connected graph with vertices and edges. Note that the graph may contain self‐loops and multiple edges. Initially, Purple teleports Blue and Orange instantaneously to a starting vertex . After the teleportation, Blue and Orange will move. In each unit of time, exactly one of the following moves is allowed:
- Blue moves along an edge from her current vertex to an adjacent vertex.
- Orange moves along an edge from his current vertex to an adjacent vertex.
- Purple uses her power to swap the positions of Blue and Orange (this swap takes one unit of time as well).
Your task is to construct a plan (or itinerary) such that both Blue and Orange, individually, visit every vertex in the cave at least once and finally return to the starting vertex .
The plan should be expressed in the following format:
- First, output an integer representing the total number of moves.
- Then output lines. Each line is one move in one of the following formats: • "B x" means Blue moves from her current vertex to an adjacent vertex . • "O x" means Orange moves from his current vertex to an adjacent vertex . • "P" means Purple swaps the positions of Blue and Orange.
It is guaranteed that the graph is connected, so a spanning tree exists. A simple solution is to perform a DFS on a spanning tree of the graph from , which produces an Euler tour. You may use the Euler tour: [ \text{tour} = [S, v_1, S, v_2, \ldots, S]]
Then, execute the tour twice. In the first phase, let Blue follow the Euler tour while keeping Orange stationary at . In the second phase, let Orange follow the same Euler tour while keeping Blue stationary at . This ensures that both Blue and Orange visit all vertices at least once and eventually return to .
inputFormat
The first line contains three integers , , and , where is the number of vertices, is the number of edges, and is the starting vertex. Each of the following lines contains two integers and , indicating that there is an undirected edge between and .
outputFormat
First, output an integer — the total number of moves in your plan. Then output lines; each line must be one of the following commands:
• "B x": Blue moves from her current vertex to an adjacent vertex . • "O x": Orange moves from his current vertex to an adjacent vertex . • "P": Purple swaps the positions of Blue and Orange.
The moves must form a valid plan such that, by the end, both Blue and Orange have each visited every vertex at least once and both are back at the starting vertex .
sample
1 0 1
0