Under construction

Still being built. Things may change

LWDB

Time limit9sMemory limit1024 MB

Summary
Paint every tree vertex within weighted distance d of a given vertex with a color, and report a vertex's current color, with later paints overriding earlier ones.
Level

Medium7 of 10

Topics
Tree, Divide and conquer
Solved
No attempts yet

Problem

The Large Wood Database (LWDB) stores any existing tree and paints it securely. The update adds new functionality, so the graph theory behind it needs another look. A weighted tree is stored in LWDB. The LWDB Management System (LWDB MS) accepts two query types:

  1. 1 v d c: paint every tree vertex whose distance from vertex vv is at most dd with color cc. Every vertex starts with color 00.
  2. 2 v: return the color of vertex vv.

You need to prototype LWDB MS and answer all user queries.

Input

The first line contains NN (1≤N≤1051 \le N \le 10^5), the number of tree vertices. Each of the next N−1N-1 lines contains three integers aia_i, bib_i, wiw_i (1≤ai,bi≤N1 \le a_i, b_i \le N, ai≠bia_i \ne b_i, 1≤wi≤1041 \le w_i \le 10^4), meaning branch ii connects vertices aia_i and bib_i with weight wiw_i. The next line contains QQ (1≤Q≤1051 \le Q \le 10^5), the number of queries. Each of the next QQ lines is one of the following:

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

Output

For each query of type 2, print the color of the requested vertex on its own line.

Examples1

  1. Example 1

    Input
    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
    
    Expected output
    6
    6
    0
    5
    7