Items and Heroes
시간 제한2초메모리 제한1024 MB
각 갱신 후 모든 정점이 자신의 부분 트리에서 필요한 아이템을 모을 수 있는지 판정한다.
문제
There is a rooted tree of vertices. The vertices are numbered by integers from to , with vertex as the root. The parent of vertex () is denoted as .
Each vertex has a box with items. Also, there is a hero in each vertex.
In the beginning, the box in vertex contains items.
In each vertex , the hero from that vertex has the quest to collect items. The hero in vertex can choose some vertices from the subtree rooted at vertex and take as many items as she wants from each of the selected vertices. One item cannot be taken by more than one hero.
Determine if it is possible for the heroes to act in such a way that all quests will be completed.
Additionally, queries are given. In the -th query, the integers , , are given, and the values are changed as follows:
- If , change the value of to .
- If , change the value of to .
The queries are applied sequentially. The changes made in each query remain for all the subsequent queries as well. After each query, determine if it is possible to complete all quests.
입력
The first line of input contains one integer ().
The second line contains integers : the parents of vertices ().
The third line contains integers ().
The fourth line contains integers ().
The fifth line contains one integer ().
Each of the following lines contains one query described by three integers , and (, , ): the type of the query, the number of vertex and the new value for (for the query of the first type) or (for the query of the second type), respectively.
출력
On the first line, print "Yes" if it is possible to complete all quests at once, or "No" otherwise.
On the following lines, print the answers for the queries in the same format, one per line.
힌트
In Example 1, the hero from vertex 1 takes two items from the box at vertex 1 and one item from the box at vertex 3, the hero from vertex 2 takes an item from the box at vertex 2, and the hero from vertex 3 takes two items from the box at vertex 3. So, all three quests are completed.
The first query changes the number of items in the box at vertex 1 from two to one. In this case, there are not enough items to complete all three quests.
The second query changes the number of items to complete the quest for the hero at vertex 3 from two to one. In this case, the hero at vertex 1 takes one item from the box at vertex 1 and two items from the box at vertex 3, the hero at vertex 2 take one item from the box at vertex 2, the hero at vertex 3 takes one item from the box at vertex 3, and all three quests are again completed.