You are given a tree of N nodes, rooted at 1. You are also given two arrays A and P, where the value of node U is given by A[U] and the parent of node U is given by P[U].
We define mex(U) as the smallest positive integer that doesn't appear in the subtree of U.
You are given a 2D array T consisting of Q queries and each query is either of the following two types:
• Type1: 1 U V: Swap the values written on nodes U and V.
• Type2: 2 U 0: Find the value of mex(U).
Find the sum of answers to queries of Type2. Since the answer can be large, return it modulo 109 + 7.
0 Comments