#P13805. [CERC 2022] Bandits

[CERC 2022] Bandits

题目描述

There is a kingdom with NN villages and N1N - 1 bidirectional roads that allow the citizens to travel between any pair of villages following a path consisting of one or more roads. The ii-th road connects villages AiA_i and BiB_i and has length CiC_i.

The king has noticed an increasing number of complaints about bandits attacking the merchants travelling along the roads in the kingdom. He has tasked his advisor with solving this problem by hiring loyal groups of thugs that will act as security agencies. Each such security contract guarantees security of all roads in a radius of RjR_j from the village XjX_j with the group’s headquarters. A road is protected by the contract if it is part of a path of length at most RjR_j from XjX_j to some other village. Some roads may be protected by several contracts and are therefore more secure.

Write a program that will process queries about new contracts and answer queries about the security of individual roads, that is the number of contracts currently securing that road.

输入格式

The first line contains the number of villages NN. The roads connecting these villages are described in the following N1N - 1 lines. The description of each road consists of space-separated integers AiA_i, BiB_i and CiC_i, which represent a road of length CiC_i between villages AiA_i and BiB_i. The villages are numbered from 1 to NN.

Next line contains the number of queries QQ. The following QQ lines describe the queries. The query that represents a new security contract starts with character '+' and is followed by the headquarters village XjX_j and security radius RjR_j. The query about the security of some road starts with character '?' and is followed by the number YjY_j of that road. The roads are numbered from 1 to N1N - 1 in order in which they are given in the input.

输出格式

Process the queries in the given order and for every query of type '?' output one line with the current number of contracts securing the road YjY_j.

7
1 2 4
4 2 7
5 1 3
3 6 4
1 6 9
2 7 1
7
+ 2 6
? 3
? 1
+ 6 14
? 1
? 2
? 3
0
1
2
0
1

提示

Input limits

  • 1N,Q1051 \leq N, Q \leq 10^5
  • 0Ci,Rj1090 \leq C_i, R_j \leq 10^9