{"raw_statement":[{"iden":"problem statement","content":"There is a tree with $N$ vertices. The $1$\\-st vertex is the root, and the parent of the $i$\\-th vertex $(2\\leq i\\leq N)$ is $p _ i\\ (1\\leq p _ i\\lt i)$.\nEach non-root vertex has an **enemy** or a **medicine** on it. Takahashi wants to defeat all the enemies. Initially, his strength is $1$, and he is at vertex $1$. For $i=2,\\ldots,N$, the information of the $i$\\-th vertex is represented by a triple of integers $(t _ i,s _ i,g _ i)$ as follows.\n\n*   If $t _ i=1$, there is an enemy at the $i$\\-th vertex. When Takahashi visits this vertex for the first time, if his strength is less than $s _ i$, Takahashi is defeated by the enemy and **loses**, after which he cannot move to other vertices. Otherwise, he defeats the enemy, and his strength increases by $g _ i$.\n*   If $t _ i=2$, there is a medicine at the $i$\\-th vertex. When Takahashi visits this vertex for the first time, he takes the medicine, and his strength is multiplied by $g _ i$. (For a vertex with a medicine, $s _ i=0$.)\n\nThere are at most $10$ vertices with a medicine.\nTakahashi can repeatedly move to an adjacent vertex. Determine if he can defeat all the enemies."},{"iden":"constraints","content":"*   $2\\leq N\\leq 500$\n*   $1\\leq p _ i\\lt i\\ (2\\leq i\\leq N)$\n*   $t _ i\\in\\lbrace1,2\\rbrace\\ (2\\leq i\\leq N)$\n*   $t _ i=1\\implies1\\leq s _ i\\leq 10 ^ 9\\ (2\\leq i\\leq N)$\n*   $t _ i=2\\implies s _ i=0\\ (2\\leq i\\leq N)$\n*   $1\\leq g _ i\\leq 10 ^ 9\\ (2\\leq i\\leq N)$\n*   There are at most $10$ vertices with $t _ i=2$.\n*   All input values are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$p _ 2$ $t _ 2$ $s _ 2$ $g _ 2$\n$p _ 3$ $t _ 3$ $s _ 3$ $g _ 3$\n$\\vdots$\n$p _ N$ $t _ N$ $s _ N$ $g _ N$"},{"iden":"sample input 1","content":"8\n1 2 0 3\n2 1 3 3\n1 2 0 4\n4 1 2 2\n1 2 0 5\n6 1 5 5\n5 1 140 1"},{"iden":"sample output 1","content":"Yes\n\nInitially, the tree looks like this:\n![image](https://img.atcoder.jp/abc319/df876b93cd1181b6e7269d978c19632b.png)\nTakahashi can defeat all the enemies by moving from vertex $1$ to $2,3,2,1,6,7,6,1,4,5,8$ in this order. Here, his position and strength change as shown in the following figure (movements to vertices that have already been visited are omitted).\n![image](https://img.atcoder.jp/abc319/de96b59f8e4b180017fbd1aba73f4fb3.png)\nOn the other hand, if he moves from vertex $1$ to $4,5,8$ in this order, for example, his strength when visiting vertex $8$ will be less than $s _ 8=140$, so he will lose without defeating all the enemies."},{"iden":"sample input 2","content":"12\n1 1 166 619\n1 1 17 592\n2 1 222 983\n2 1 729 338\n5 1 747 62\n3 1 452 815\n3 2 0 1\n4 2 0 40\n4 1 306 520\n6 1 317 591\n1 1 507 946"},{"iden":"sample output 2","content":"No"},{"iden":"sample input 3","content":"12\n1 1 1 791\n2 2 0 410\n2 1 724 790\n2 1 828 599\n5 2 0 13\n3 1 550 803\n1 1 802 506\n5 1 261 587\n6 1 663 329\n8 1 11 955\n9 1 148 917"},{"iden":"sample output 3","content":"Yes"},{"iden":"sample input 4","content":"12\n1 2 0 1000000000\n2 2 0 1000000000\n3 2 0 1000000000\n4 2 0 1000000000\n5 2 0 1000000000\n6 2 0 1000000000\n7 2 0 1000000000\n8 2 0 1000000000\n9 2 0 1000000000\n10 2 0 1000000000\n11 1 1 1"},{"iden":"sample output 4","content":"Yes"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}