#P8119. Rainbow Dragon Cave Tour

    ID: 21302 Type: Default 1000ms 256MiB

Rainbow Dragon Cave Tour

Rainbow Dragon Cave Tour

In the problem, the interior of Honglong Cave is abstracted as an undirected connected graph with nn vertices and mm edges. Note that the graph may contain self‐loops and multiple edges. Initially, Purple teleports Blue and Orange instantaneously to a starting vertex SS. After the teleportation, Blue and Orange will move. In each unit of time, exactly one of the following moves is allowed:

  1. Blue moves along an edge from her current vertex to an adjacent vertex.
  2. Orange moves along an edge from his current vertex to an adjacent vertex.
  3. 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 SS.

The plan should be expressed in the following format:

  • First, output an integer kk representing the total number of moves.
  • Then output kk 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 xx. • "O x" means Orange moves from his current vertex to an adjacent vertex xx. • "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 SS, 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 SS. In the second phase, let Orange follow the same Euler tour while keeping Blue stationary at SS. This ensures that both Blue and Orange visit all vertices at least once and eventually return to SS.

inputFormat

The first line contains three integers nn, mm, and SS, where nn is the number of vertices, mm is the number of edges, and SS is the starting vertex. Each of the following mm lines contains two integers uu and vv, indicating that there is an undirected edge between uu and vv.

outputFormat

First, output an integer kk — the total number of moves in your plan. Then output kk lines; each line must be one of the following commands:

• "B x": Blue moves from her current vertex to an adjacent vertex xx. • "O x": Orange moves from his current vertex to an adjacent vertex xx. • "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 SS.

sample

1 0 1
0