QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#10772. 道馆之战

الإحصائيات

口袋妖怪(又名神奇宝贝或宠物小精灵)红/蓝/绿宝石中的水系道馆需要经过三个冰地才能到达馆主的面前,冰地中的每一个冰块都只能经过一次。当一个冰地上的所有冰块都被经过之后,到下一个冰地的楼梯才会被打开。三个冰地分别如下:

problem_10772_1.jpeg problem_10772_2.jpeg

第一个泳池

problem_10772_3.jpeg problem_10772_4.jpeg

第二个泳池

problem_10772_5.jpeg

第三个泳池

当走出第三个冰地之后,就可以与馆主进行道馆战了。馆主发现这个难度太小,导致经常有挑战者能通过,为了加大难度,将道馆分成了 $n$ 个房间,每个房间中是两个冰块或障碍,表示一列冰地。任意两个房间之间均有且仅有一条路径相连,即这 $n$ 个房间构成一个树状结构。每个房间分成了 $A$ 和 $B$ 两个区域,每一区域都是一个薄冰块或者障碍物。每次只能移动到相邻房间的同一类区域(即若你现在在这个房间的 $A$ 区域,那么你只能移动到相邻房间的 $A$ 区域)或这个房间的另一区域。现在挑战者从房间 $u$ 出发,馆主在房间 $v$,那么挑战者只能朝接近馆主所在房间的方向过去。一开始挑战者可以在房间 $u$ 的任意一个冰块区域内。如果挑战者踩过的冰块数达到了最大值(即没有一种方案踩过的冰块数更多了),那么当挑战者走到最后一个冰块上时,他会被瞬间传送到馆主面前与馆主进行道馆战。自从馆主修改规则后已经经过了 $m$ 天,每天要么是有一个挑战者来进行挑战,要么就是馆主将某个房间进行了修改。对于每个来的挑战者,你需要计算出他若要和馆主进行战斗需要经过的冰块数。

输入格式

第一行包含两个正整数 $n$ 和 $m$。 第 2 行到第 $n$ 行,每行包含两个正整数 $x$ 和 $y$,表示一条连接房间 $x$ 和房间 $y$ 的边。房间编号为 $1 \ldots n$。 接下来 $n$ 行,每行包含两个字符。第 $n + k$ 行表示房间 $k$ 的两个区域,第一个字符为 $A$ 区域,第二个字符为 $B$ 区域。其中 “.” 表示是薄冰块,“#” 表示是障碍物。 最后的 $m$ 行,每行一个操作:

  • C u s:将房间 $u$ 里的两个区域修改为字符串 s(长度为 2,由 “.” 或 “#” 构成)。
  • Q u v:询问挑战者在房间 $u$,馆主在房间 $v$ 时,挑战者能与馆主进行挑战需要踩的冰块数。如果房间 $u$ 的两个区域都是障碍物,那么输出 0。

输出格式

包含若干行,每行一个整数。即对于输入中的每个询问,依次输出一个答案。

样例数据

样例输入

5 3
1 2
2 3
2 4
1 5
.#
..
#.
.#
..
Q 5 3
C 1 ##
Q 4 5

样例输出

6
3

样例说明

第一个询问,从房间5出发经过的冰块数最多的路径为:

problem_10772_1.png

第二个询问,从房间4出发经过的冰块数最多的路径为:

problem_10772_2.png

数据范围与提示

数据编号 $n$ $m$ 说明
1 $\le 1\, 000$ $\le 10\,000$ 无。
2, 3, 4 $\le 3\, 000$ $\le 50\,000$ 没有 C 操作。
5, 6, 7 $\le 30\, 000$ $\le 80\,000$ 房间 $i$ 与房间 $i+1$ 相连。 ($1 \leq i < n$)
8, 9, 10 无。
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.