Problem of the day
Input:
'N' = 5, βKβ = 3
βARRβ = [-1, 0, 0, 1, 2]
βLOCKβ = [0, 0, 1, 0, 0]
Output: β1β
In the above tree in the simple path from node β4β to root β1,β the nodes encountered are [0, 1, 3], and no node from the set is locked. Hence node β3β can be locked.
The first line will contain the integer 'T', the number of test cases. For each test case
The first line of each test case contains two integers βNβ, and βKβ.
The second line of each test case contains βNβ integers denoting the parent of node βiβ.
The third line of each test case contains βNβ integers denoting elements of array βLOCKβ.
For each test case, print β1β or β0β, denoting whether the node can be locked.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= 'T' <= 10
1 <= 'N' <= 10^5
0 <= βKβ <= βN-1β
0 <= βPAR[i]β <= βN-1β
0 <= βLOCK[i]β <= 1
Time Limit: 1 sec
2
5 0
-1 0 3 0 3
1 1 1 0 0
4 1
3 2 -1 1
1 0 0 1
0
1
In the first test case,
In the above tree the target node β0β is itself locked, so it cannot be locked.
Hence the answer is βfalseβ.
In the second test case,
In the above tree in the simple path from node β1β to root β2β the nodes encountered are [1, 2], and no node from the set is locked.
Hence the answer is βtrueβ.
2
4 2
-1 0 1 1
0 1 0 0
4 3
-1 0 1 2
1 0 0 0
0
0