LWDB

시간 제한9초메모리 제한1024 MB

요약
가중 트리에서 정점 v로부터 가중 거리 d 이내의 모든 정점을 다시 칠하는 갱신과 한 정점의 색을 묻는 질의를 처리한다.
난이도

어려움10점 중 8점

유형
트리, 분할 정복, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

The Large Wood Database is created to securely store and paint any existing tree. Update for LWDB provides new functionality, so it is time to think over the graph theory. A weighed tree is stored in the LWDB. In the query language for LWDB Management System (LWDB MS) two types of queries are available:

  1. <<11 vv dd cc>> --- paint all tree-vertices at the distance not exceeding dd from the vertice vv in color cc. Initial color for any vertices is 00.
  2. <<22 vv>> --- return the color of the vertice vv.

It is required to prototype LWDB MS and respond to all user’s queries.

입력

The first line contains an integer NN (1≤N≤1051 \le N \le 10^5) --- the number of tree vertices. The following N-1 lines contain the description of branches, three numbers in each line a_ia\_i, b_ib\_i, w_iw\_i (1≤a_i,b_i≤N1 \le a\_i, b\_i \le N, a_i≠b_ia\_i \ne b\_i, 1≤w_i≤1041 \le w\_i \le 10^4), where ii-th branch with weight w_iw\_i connects vertices a_ia\_i and b_ib\_i. The next line contains integer Q (1≤Q≤1051 \le Q \le 10^5) --- number of queries. In each of Q following lines there are two types of queries:

  1. Numbers 1, vv, dd, cc (1≤v≤N1 \le v \le N, 0≤d≤1090 \le d \le 10^9, 0≤c≤1090 \le c \le 10^9).
  2. Numbers 2, vv (1≤v≤N1 \le v \le N).

Input numbers are integers.

출력

For each second type query output the color of requested vertice in a separate line.

예제1

  1. 예제 1

    입력
    5
    1 2 30
    1 3 50
    3 4 70
    3 5 60
    8
    1 3 72 6
    2 5
    1 4 60 5
    2 3
    2 2
    1 2 144 7
    2 4
    2 5
    
    예상 출력
    6
    6
    0
    5
    7