LWDB
시간 제한9초메모리 제한1024 MB
가중 트리에서 정점 v로부터 가중 거리 d 이내의 모든 정점을 다시 칠하는 갱신과 한 정점의 색을 묻는 질의를 처리한다.
문제
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:
- << >> --- paint all tree-vertices at the distance not exceeding from the vertice in color . Initial color for any vertices is .
- << >> --- return the color of the vertice .
It is required to prototype LWDB MS and respond to all user’s queries.
입력
The first line contains an integer () --- the number of tree vertices. The following N-1 lines contain the description of branches, three numbers in each line , , (, , ), where -th branch with weight connects vertices and . The next line contains integer Q () --- number of queries. In each of Q following lines there are two types of queries:
- Numbers 1, , , (, , ).
- Numbers 2, ().
Input numbers are integers.
출력
For each second type query output the color of requested vertice in a separate line.