#P2892. [NOI2007] 追捕盗贼

    ID: 2996 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2007NOI 系列提交答案Special JudgeO2优化

[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 NN cities, and these NN cities are connected by exactly N1N-1 roads so that any two cities can be reached via some sequence of roads. From a data structure perspective, these NN cities and N1N-1 roads form a tree.

For example, the following diagram shows one possible layout of Magic Land (44 cities labeled with numbers, 33 roads labeled with letters):

Frank can move along roads at any speed.

For instance, in the layout above, within 0.000010.00001 seconds (or any arbitrarily short period of time), Frank can go from city 11 through city 22 to city 44, passing along two roads.

Capturing Frank alive is extremely difficult, so the Bureau has dispatched experienced detectives with exceptional pursuit skills:

  1. If a detective and Frank are in the same city, the detective immediately detects Frank and arrests him.
  2. 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:

  1. 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 xx. It takes 11 second.
  2. 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 xx is recalled to headquarters. It takes 11 second.
  3. Move a detective in city xx along a road to city yy. This operation is denoted as M x y. It takes 11 second. Of course, this requires that there is a road between cities xx and yy. 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:

  1. L 2: Airdrop a detective into city 22. Note that after this step is completed, Frank cannot be in city 22, otherwise he would have been captured.
  2. L 2: Airdrop another detective into city 22.
  3. M 2 1: Move one detective from city 22 to city 11. Note that another detective remains in city 22. After this step, Frank cannot be in city 11, nor on road AA. In other words, if Frank has not been arrested yet, he can only be in city 33 or city 44, or on road BB or road CC.
  4. B 1: Recall the detective in city 11. Note that although this detective is recalled, since we have kept a detective guarding city 22 the whole time, Frank still cannot get to city 11 or road AA.
  5. L 3: Airdrop a detective into city 33. Note that this step can airdrop the detective who was recalled earlier. After this step is completed, Frank cannot be in city 33, otherwise he would be captured.
  6. M 3 2: Move a detective from city 33 to city 22. After this step, if Frank has still not been captured, then he can only be on road CC or in city 44. Note that after this step there are two detectives in city 22.
  7. M 2 4: Move a detective from city 22 to city 44. After this step, Frank is guaranteed to be captured, unless he never came to Magic Land at all.

This plan requires a total of 22 detectives. It can be proved that if at all times only 11 detective (or fewer) participates, Frank will escape.

Your task is simple: for a given layout of Magic Land, compute SS, 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 NN, the number of cities, numbered 11 to NN.

The next N1N-1 lines each contain two integers xi,yix_i,y_i separated by a space, indicating that cities xix_i and yiy_i are connected by a road. It is guaranteed that 1xi,yiN1\le x_i,y_i \le N.

Output Format

Output your capture plan.

On the first line, output an integer SS, the number of detectives required by your plan.

On the second line, output an integer TT, the total number of steps in your plan.

Then output TT 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 xx, meaning a detective is airdropped into city xx. You must ensure 1xN1\le x\le N.

B x, where B is an uppercase letter, followed by a space, then an integer xx, meaning a detective in city xx is recalled. You must ensure 1xN1\le x\le N, and that prior to this step, there is indeed at least one detective in city xx.

M x y, where M is an uppercase letter, followed by a space, then an integer xx, followed by a space, and finally an integer yy, meaning a detective in city xx moves along a road to city yy. You must ensure 1x,yN1\le x,y\le N, that prior to this step there is indeed at least one detective in city xx, and that there is a road between cities xx and yy.

You must ensure that the output SS 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 TT exceeds 2000020000, or after the plan ends Frank is not guaranteed to be captured, you will receive no points.

Otherwise, compare your output SS with our known optimal answer SS ^* :

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

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

Translated by ChatGPT 5