#3164. [POI2007] MEG-Megalopolis
[POI2007] MEG-Megalopolis
[POI2007] MEG-Megalopolis
题目描述
在经济全球化浪潮的影响下,习惯于漫步在清晨的乡间小路的邮递员Blue Mary也开始骑着摩托车传递邮件了。不过,她经常回忆起以前在乡间漫步的情景。昔日,乡下有依次编号为1..n的n个小村庄,某些村庄之间有一些双向的土路。从每个村庄都恰好有一条路径到达村庄1(即比特堡)。并且,对于每个村庄,它到比特堡的路径恰好只经过编号比它的编号小的村庄。另外,对于所有道路而言,它们都不在除村庄以外的其他地点相遇。在这个未开化的地方,从来没有过高架桥和地下铁道。随着时间的推移,越来越多的土路被改造成了公路。至今,Blue Mary还清晰地记得最后一条土路被改造为公路的情景。现在,这里已经没有土路了——所有的路都成为了公路,而昔日的村庄已经变成了一个大都市。 Blue Mary想起了在改造期间她送信的经历。她从比特堡出发,需要去某个村庄,并且在两次送信经历的间隔期间,有某些土路被改造成了公路.现在Blue Mary需要你的帮助:计算出每次送信她需要走过的土路数目。(对于公路,她可以骑摩托车;而对于土路,她就只好推车了。)
输入格式
In the first line of the standard input there is a single integer (),denoting the number of villages in Byteotia. The following lines contain descriptions of the roads, in the form of two integers , ()separated by a single space, denoting the numbers of villages connected with a road. Inthe next line there is a single integer (),denoting the number of trips Byteasar has made.
The following lines contain descriptions of the events, in chronological order:
A description of the form "A "(for ) denotes a country road between villages and beingtransformed into a motorway in that particular moment.
A description of the from "W " denotes Byteasar's trip from Bitburg to village .
输出格式
Your programme should write out exactly integers to the standard output, one a line, denoting the numberof country roads Byteasar has travelled during his successive trips.
样例 #1
样例输入 #1
5
1 2
1 3
1 4
4 5
4
W 5
A 1 4
W 5
A 4 5
W 5
W 2
A 1 2
A 1 3
样例输出 #1
2
1
0
1