Bandits

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

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 A_iA\_i and B_iB\_i and has length C_iC\_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 R_jR\_j from the village X_jX\_j with the group's headquarters. A road is protected by the contract if it is part of a path of length at most R_jR\_j from X_jX\_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 A_iA\_i, B_iB\_i and C_iC\_i, which represent a road of length C_iC\_i between villages A_iA\_i and B_iB\_i. The villages are numbered from 11 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 X_jX\_j and security radius R_jR\_j. The query about the security of some road starts with character '?' and is followed by the number Y_jY\_j of that road. The roads are numbered from 11 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 Y_jY\_j.

제한

  • 1N,Q1051 \leq N, Q \leq 10^5
  • 0C_i,R_j1090 \leq C\_i, R\_j \leq 10^9