#P4216. [SCOI2015] 情报传递
[SCOI2015] 情报传递
Description
Knight Company is a huge intelligence organization with a vast intelligence network. There are agents in the network. Each agent may have several (possibly none) subordinates. Except for one boss, each of the remaining agents has exactly one supervisor. The company has strict discipline: each agent may contact only their own supervisor and subordinates. Meanwhile, any two agents can pass intelligence through the network.
Each day, the company assigns exactly one of the following two tasks:
- Collect intelligence: designate agent to start collecting intelligence.
- Transmit intelligence: transmit a piece of intelligence from agent to agent .
Initially, all agents are in a dormant stage and are relatively safe; we consider their danger values to be . Once an agent starts collecting intelligence, their danger value keeps increasing by per day (on the starting day, the danger value is still ; on the 2nd day it is ; on the 3rd day it is ; and so on). Transmission tasks do not increase any agent’s danger value.
To ensure safety during transmission, each piece of intelligence has a risk control value . Among all agents who participate in transmitting this piece (i.e., those on the unique path between and , inclusive), any agent whose danger value is greater than is considered a threat to this piece.
For every transmission task, determine how many agents participate in the transmission and how many of them constitute a threat to this piece.
Input Format
- The first line contains a positive integer , the number of agents.
- The second line contains non-negative integers. The -th integer denotes the supervisor of agent . In particular, if , agent is the boss.
- The third line contains a positive integer , the number of tasks (one per day).
- The next lines each describe a task. Each line starts with a positive integer :
- If , it is a transmission task, followed by three positive integers , , , denoting the start, the end, and the risk control value, respectively.
- If , it is a collection task, followed by one positive integer , the agent who starts collecting intelligence.
Output Format
For each transmission task, output one line containing two integers: the number of participating agents and the number of agents who constitute a threat to this piece of intelligence.
7
0 1 1 2 2 3 3
6
1 4 7 0
2 1
2 4
2 7
1 4 7 1
1 4 7 3
5 0
5 2
5 1
Hint
Sample explanation:
For the transmission tasks, each passes through agents, namely , , , , and .
- In the 1st task, all agents (danger value ) do not constitute a threat.
- In the 2nd task, there are threatening agents: agent (danger value ) and agent (danger value ). Agent (danger value ) is not a threat.
- In the 3rd task, only agent is a threat.
Constraints:
, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号