#P2892. [NOI2007] 追捕盗贼
[NOI2007] 追捕盗贼
Description
A notorious thief named Frank has recently appeared in the magical kingdom Magic Land. He commits crimes all over Magic Land, specializing in stealing confidential government documents (so some suspect Frank is a spy sent by an enemy nation).
To capture Frank, the Security Bureau of Magic Land is taking strong action!
Magic Land consists of cities, and these cities are connected by exactly roads so that any two cities can be reached via some sequence of roads. From a data structure perspective, these cities and roads form a tree.
For example, the following diagram shows one possible layout of Magic Land ( cities labeled with numbers, roads labeled with letters):

Frank can move along roads at any speed.
For instance, in the layout above, within seconds (or any arbitrarily short period of time), Frank can go from city through city to city , passing along two roads.
Capturing Frank alive is extremely difficult, so the Bureau has dispatched experienced detectives with exceptional pursuit skills:
- If a detective and Frank are in the same city, the detective immediately detects Frank and arrests him.
- Although Frank can move arbitrarily fast along roads, if a detective and Frank meet on the same road, the detective can also immediately detect Frank and arrest him.
The Bureau has no idea which city Frank is hiding in, nor on which road he might be moving, so they must devise a meticulous capture plan consisting of several steps. In each step, exactly one of the following actions can be performed:
- Airdrop a detective into some city. A detective can be airdropped directly from headquarters into any city in Magic Land. This operation is denoted as
L x, meaning a detective is airdropped into city . It takes second. - Recall a detective who is staying in some city back to headquarters, to be available for later airdrop into some city. This operation is denoted as
B x, meaning a detective in city is recalled to headquarters. It takes second. - Move a detective in city along a road to city . This operation is denoted as
M x y. It takes second. Of course, this requires that there is a road between cities and . If, during the detective’s move, Frank is also on the same road, then the detective will capture Frank.
Now it is your turn to devise a capture plan, i.e., to output a sequence of steps, ensuring that no matter where Frank initially hides and no matter how cunningly he moves throughout the process (Frank might steal the plan, so he will try every means to evade capture), he is guaranteed to be apprehended.
We want to use as few detectives as possible, since experienced detectives are scarce.
For the layout shown earlier, one feasible plan is as follows:
L 2: Airdrop a detective into city . Note that after this step is completed, Frank cannot be in city , otherwise he would have been captured.L 2: Airdrop another detective into city .M 2 1: Move one detective from city to city . Note that another detective remains in city . After this step, Frank cannot be in city , nor on road . In other words, if Frank has not been arrested yet, he can only be in city or city , or on road or road .B 1: Recall the detective in city . Note that although this detective is recalled, since we have kept a detective guarding city the whole time, Frank still cannot get to city or road .L 3: Airdrop a detective into city . Note that this step can airdrop the detective who was recalled earlier. After this step is completed, Frank cannot be in city , otherwise he would be captured.M 3 2: Move a detective from city to city . After this step, if Frank has still not been captured, then he can only be on road or in city . Note that after this step there are two detectives in city .M 2 4: Move a detective from city to city . After this step, Frank is guaranteed to be captured, unless he never came to Magic Land at all.
This plan requires a total of detectives. It can be proved that if at all times only detective (or fewer) participates, Frank will escape.
Your task is simple: for a given layout of Magic Land, compute , the minimum number of detectives required to capture Frank, and output a corresponding capture plan.
Input Format
The input file gives the layout of Magic Land.
The first line contains an integer , the number of cities, numbered to .
The next lines each contain two integers separated by a space, indicating that cities and are connected by a road. It is guaranteed that .
Output Format
Output your capture plan.
On the first line, output an integer , the number of detectives required by your plan.
On the second line, output an integer , the total number of steps in your plan.
Then output lines, each describing one step of the plan. Each line must be in one of the following three forms:
L x, where L is an uppercase letter, followed by a space, then an integer , meaning a detective is airdropped into city . You must ensure .
B x, where B is an uppercase letter, followed by a space, then an integer , meaning a detective in city is recalled. You must ensure , and that prior to this step, there is indeed at least one detective in city .
M x y, where M is an uppercase letter, followed by a space, then an integer , followed by a space, and finally an integer , meaning a detective in city moves along a road to city . You must ensure , that prior to this step there is indeed at least one detective in city , and that there is a road between cities and .
You must ensure that the output is exactly the number of detectives used by your plan.
4
1 2
3 2
2 4
2
7
L 2
L 2
M 2 1
B 1
L 3
M 3 2
M 2 4
Hint
For any test point:
If the output plan is invalid, or the total number of steps exceeds , or after the plan ends Frank is not guaranteed to be captured, you will receive no points.
Otherwise, compare your output with our known optimal answer :
- If , you get of the points.
- If , you get of the points.
- If , you get of the points.
- If , you get of the points.
- If , you get of the points.
- If , you get of the points.
The input is guaranteed to describe a connected tree with nodes, .
Translated by ChatGPT 5
京公网安备 11011102002149号