当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4875:ZCC loves Army

题目描述
ZCC owns an army with n soldiers. Soldiers are numbered from 1 to n. Soldier 1 is the commander in chief. Each soldier has a direct superior (which is called father in ACM) except soldier 1. x is a direct inferior (which is called son in ACM) of y if and only if y is the direct superior of x. Soldier use an ordered list called direct inferiors list to manage his direct inferiors (The indexes begin with 1). If soldier A and soldier B are in the same direct inferiors list, and A is in front of B, then we say A’s level is higher than B. We assume that soldier 1 belongs to a direct inferior list that only contains soldier 1 for convenience.
Messages can be transmitted among the soldiers. A soldier can directly send messages to his direct superior, his direct inferior, and those who are in the same direct inferior list with him. Messages can also be sent indirectly. That means if x wants to send a message to y, he first send it directly to a third soldier z, then z send this message directly to y. In this case, we say z is involved in this transmission as a middleman. Message transmission that involves more than one middleman is also allowed.
Orders can be transmitted among the soldiers too. A soldier can directly give orders to his direct inferior and those who are in the same direct inferior list with him but have lower level. Orders can also be given indirectly. That means if x wants to give an order to y, he first give it to a third soldier z, then z give this order to y. In this case, we say z is involved in this transmission as a middleman. Order transmission that involves more than one middleman is also allowed.
Unfortunately, sometimes some soldiers will change their direct superior. More specifically, event like “the p-th soldier to (p+c-1)-th soldier in soldier x’s direct inferior list change their direct superior to y and be inserted after the q-th soldier in y’s direct inferior list (if q=0, that means these soldiers are inserted in front of the first soldier in y’s direct inferior list)” will sometimes happen.
To examine the efficiency of the transmission of the messages and orders, ZCC will ask two types of question:
1) If soldier x want to send messages to soldier y, at least how many soldiers will be involved in this transmission as a middleman.
2) How many soldiers can give orders to soldier x.
Now, m events, including direct superior change events and ZCC’s questions, happen one by one. Can you answer all ZCC’s questions?
输入解释
The first line contains two integers n and m, indicating the number of soldiers and the number of events.
Then n lines follow, describing the initial direct inferior list of each soldier. The i-th line contains several integers. The first integer is k, indicating the number of soldier i’s direct inferior. Then k integers follow, indicating the direct inferior list of soldier i.
After that m lines follow, describing the m events. Each line begins with an integer t, indicating the type of this event.
If t = 1, then 5 integers x, p, c, y and q follow, indicating a direct superior change event;
If t = 2, then 2 integers x and y follow, indicating ZCC’s question 1;
If t = 3, then an integer x follows, indicating ZCC’s question 2.
输出解释
For each question, output one line with one integer indicating your answer.
输入样例
9 7
2 2 3
3 4 5 6
3 7 8 9
0
0
0
0
0
0
3 1
3 9
1 2 2 2 3 2
3 9
2 5 9
2 4 8
3 3
输出样例
0
5
7
0
2
2

提示
   n<=100000, m<=100000
   You can assume that the events are all legal, and the relationship among the soldiers forms a tree all the time.
来自杭电HDUOJ的附加信息
Author 镇海中学
Recommend

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-4875

最后修改于 2020-10-25T23:17:40+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2500/1200MS(Java/Others) 65536/65536K(Java/Others)