编程介的小学生 2017-08-22 03:16 采纳率: 20.5%
浏览 649
已采纳

Hilarity

Problem Description
After June 1st, elementary students of Ted Land are still celebrating "The Sacred Day of Elementary Students”. They go to the streets and do some elementary students stuff. So we call them "elementary students". There are N cities in Ted Land. But for simplicity, the mayor Matt only built N - 1 roads so that all cities can reach each other. Some of the roads are occupied by the "elementary students". They will put an celebration hat on everyone who goes through the road without one. But if someone goes through the road with a celebration hat on his head, "elementary students" will steal the hat for no reason. Since Matt doesn’t have a celebration hat, he wants to know how many different paths in his land that he can end up with a hat. Two paths are considered to be different if and only if they have different start city or end city. As the counsellor of the mayor Matt, you have to answer this question for him. The celebration elementary students are not stable: sometimes a new crowd of elementary students go to an empty road; sometimes the elementary students on a road will go back home and remain the road empty. Matt will send you the monitor about the change of elementary students on road and ask you the question above. You will be fired if you answer wrong.

Input
The first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow.

For each test case, the first line contains N (1<=N<=30000) describing the number of cities.

Then N lines follow. The ith line of these contains the name of the ith city, it’s a string containing only letters and will not be longer than 10.

The following N - 1 lines indicate the N - 1 edges between cities. Each of these lines will contain two strings for the cities’ name and a integer for the initial status of the edge (0 for empty, 1 for crowded).

Then an integer M (1<=M<=60000) describes the number of queries. There are two kinds of query:

● "M i" means the status changing of the ith (starting from 1) road (0 to 1, 1 to 0);
● "Q" means that Matt asks you the number of different paths.

Output
For each test case, first output one line “Case #x:”, where x is the case number (starting from 1).

Then for each “Q” in input, output a line with the answer.

Sample Input
1
5
a
b
c
d
e
a b 1
b c 0
c d 1
d e 1
7
Q
M 1
Q
M 3
Q
M 4
Q

Sample Output
Case #1:
12
8
8
0

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-09-03 14:31
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。