QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 128 MB 満点: 100

#12672. Catching the Thief

統計

In the magical land of Magic Land, a notorious thief named Frank has recently appeared. He has been committing crimes all over Magic Land, specifically stealing confidential documents from government agencies (leading some to suspect that Frank is a spy sent by an enemy nation). To catch Frank, the Security Bureau of Magic Land has launched a major operation!

Magic Land consists of $N$ cities, and these $N$ cities are connected by exactly $N-1$ roads such that any two cities can reach each other through a series of roads. From a data structure perspective, we can say that these $N$ cities and $N-1$ roads form a tree.

For example, the following diagram shows a possible layout of Magic Land (4 cities numbered with digits, 3 roads labeled with letters):

The thief Frank can move along the roads at any speed. For instance, in the layout given above, in 0.00001 seconds (or any arbitrarily short period of time), Frank can travel from city 1 through city 2 to reach city 4, passing through two roads in the process.

Capturing Frank is difficult, so the Security Bureau has dispatched experienced detectives who possess extraordinary tracking talents:

  1. As long as a detective and Frank are in the same city, the detective can immediately detect Frank and arrest him.
  2. Although Frank can move along the roads at any speed, if a detective and Frank meet on the same road, the detective can also immediately detect Frank and arrest him.

The Security Bureau does not know which city Frank is hiding in, or which road he is currently moving on, so they need to formulate a meticulous capture plan consisting of several steps. In each step, one of the following actions can be performed:

  1. Air-drop a detective into a city. A detective can be air-dropped directly from headquarters into any city in Magic Land. This operation is denoted as "L x", meaning to air-drop a detective into the city numbered $x$. This takes 1 second.
  2. Recall a detective currently in a city back to headquarters, to be available for air-dropping into a city in future steps. This operation is denoted as "B x", meaning to recall a detective from the city numbered $x$. This takes 1 second.
  3. Let a detective in city $x$ move along a road to city $y$. This operation is denoted as "M x y". This takes 1 second. Of course, this requires that there is a road between city $x$ and city $y$. If, during the detective's movement, the thief Frank is also on the same road, the detective catches Frank.

Now, it is your turn to formulate a capture plan, which means providing a series of steps, ensuring that no matter where the thief Frank starts, and no matter how cunningly Frank moves throughout the process (Frank might steal the capture plan, so he will definitely try his best to escape), he will definitely be brought to justice.

The fewer detectives involved, the better, as experienced detectives are scarce.

Input

The input file provides the layout of Magic Land. The first line contains an integer $N$, representing $N$ cities, with city numbers from $1$ to $N$. The next $N-1$ lines each contain two space-separated integers $x_i, y_i$, representing that there is a road between city $x_i$ and city $y_i$. It is guaranteed that $1 \le x_i, y_i \le N$.

Output

Output your capture plan to the output file. The first line should output an integer $S$, representing the number of detectives required for the capture plan. The second line should output an integer $T$, representing the total number of steps in the capture plan. Next, output $T$ lines, describing each step of the capture plan in order. Each line must be one of the following three forms:

  • "L x", where L is an uppercase letter, followed by a space, and then an integer $x$, representing the air-drop of a detective into city $x$. You must ensure $1 \le x \le N$.
  • "B x", where B is an uppercase letter, followed by a space, and then an integer $x$, representing the recall of a detective from city $x$. You must ensure $1 \le x \le N$, and that there is at least one detective in city $x$ before this step is executed.
  • "M x y", where M is an uppercase letter, followed by a space, then an integer $x$, a space, and finally an integer $y$. This represents moving a detective from city $x$ along a road to city $y$. You must ensure $1 \le x, y \le N$, that there is at least one detective in city $x$ before this step is executed, and that there is a road between city $x$ and city $y$.

You must ensure that the output $S$ is indeed equal to the number of detectives required in the capture plan.

Examples

Input 1

4
1 2
3 2
2 4

Output 1

2
7
L 2
L 2
M 2 1
B 1
L 3
M 3 2
M 2 4

Subtasks

For any test case: If the output capture plan is invalid, or the total number of steps $T$ exceeds 20000, or the capture of Frank cannot be guaranteed after the plan ends, no points will be awarded. Otherwise, compare your output $S$ with our known standard answer $S^*$:

  1. If $S < S^*$, you get 120% of the points.
  2. If $S = S^*$, you get 100% of the points.
  3. If $S^* < S \le S^* + 2$, you get 60% of the points.
  4. If $S^* + 2 < S \le S^* + 4$, you get 40% of the points.
  5. If $S^* + 4 < S \le S^* + 8$, you get 20% of the points.
  6. If $S > S^* + 8$, you get 10% of the points.

Constraints

The input is guaranteed to describe a connected tree with $N$ nodes, $1 \le N \le 1000$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.