{"raw_statement":[{"iden":"statement","content":"Harry, upon inquiring Helena Ravenclaw's ghost, came to know that she told Tom Riddle or You-know-who about Rowena Ravenclaw's diadem and that he stole it from her.\n\nHarry thought that Riddle would have assumed that he was the only one to discover the Room of Requirement and thus, would have hidden it there. So Harry is trying to get inside the Room of Requirement to destroy the diadem as he knows that it is a horcrux.\n\nBut he has to answer a puzzle in order to enter the room. He is given _n_ objects, numbered from 1 to _n_. Some of the objects have a parent object, that has a lesser number. Formally, object _i_ may have a parent object _parent__i_ such that _parent__i_ < _i_.\n\nThere is also a type associated with each parent relation, it can be either of type 1 or type 2. Type 1 relation means that the child object is like a special case of the parent object. Type 2 relation means that the second object is **always** a part of the first object and all its special cases.\n\nNote that if an object _b_ is a special case of object _a_, and _c_ is a special case of object _b_, then _c_ is considered to be a special case of object _a_ as well. The same holds for parts: if object _b_ is a part of _a_, and object _c_ is a part of _b_, then we say that object _c_ is a part of _a_. Also note, that if object _b_ is a part of _a_, and object _c_ is a special case of _a_, then _b_ is a part of _c_ as well.\n\nAn object is considered to be neither a part of itself nor a special case of itself.\n\nNow, Harry has to answer two type of queries:\n\n*   _1 u v_: he needs to tell if object _v_ is a special case of object _u_.\n*   _2 u v_: he needs to tell if object _v_ is a part of object _u_."},{"iden":"input","content":"First line of input contains the number _n_ (1 ≤ _n_ ≤ 105), the number of objects.\n\nNext _n_ lines contain two integer _parent__i_ and _type__i_ ( - 1 ≤ _parent__i_ < _i_ _parent__i_ ≠ 0,  - 1 ≤ _type__i_ ≤ 1), implying that the _i_\\-th object has the parent _parent__i_. (If _type__i_ = 0, this implies that the object _i_ is a special case of object _parent__i_. If _type__i_ = 1, this implies that the object _i_ is a part of object _parent__i_). In case the _i_\\-th object has no parent, both _parent__i_ and _type__i_ are _\\-1_.\n\nNext line contains an integer _q_ (1 ≤ _q_ ≤ 105), the number of queries.\n\nNext _q_ lines each represent a query having three space separated integers _type__i_, _u__i_, _v__i_ (1 ≤ _type__i_ ≤ 2, 1 ≤ _u_, _v_ ≤ _n_)."},{"iden":"output","content":"Output will contain _q_ lines, each containing the answer for the corresponding query as \"_YES_\" (affirmative) or \"_NO_\" (without quotes).\n\nYou can output each letter in any case (upper or lower)."},{"iden":"examples","content":"Input\n\n3\n-1 -1\n1 0\n2 0\n2\n1 1 3\n2 1 3\n\nOutput\n\nYES\nNO\n\nInput\n\n3\n-1 -1\n1 0\n1 1\n2\n2 2 3\n2 3 2\n\nOutput\n\nYES\nNO"},{"iden":"note","content":"In test case 1, as object 2 is a special case of object 1 and object 3 is a special case of object 2, this makes object 3 a special case of object 1.\n\nIn test case 2, as object 2 is a special case of object 1 and object 1 has object 3, this will mean that object 2 will also have object 3. This is because when a general case (object 1) has object 3, its special case (object 2) will definitely have object 3."}],"translated_statement":[{"iden":"statement","content":"哈利在向赫尔加·拉文克劳的幽灵询问后得知，她曾向汤姆·里德尔或“你懂的谁”透露了罗伊纳·拉文克劳的冠冕，并且他从她那里偷走了它。\n\n哈利认为，里德尔会假设自己是唯一发现“需求室”的人，因此他会把冠冕藏在那里。于是哈利试图进入“需求室”以摧毁冠冕，因为他知道它是一个魂器。\n\n但为了进入房间，他必须解答一个谜题。他被给予 #cf_span[n] 个物体，编号从 #cf_span[1] 到 #cf_span[n]。某些物体具有父物体，其编号更小。形式上，物体 #cf_span[i] 可能有一个父物体 #cf_span[parenti]，满足 #cf_span[parenti < i]。\n\n每条父子关系都有一个类型，可以是类型 #cf_span[1] 或类型 #cf_span[2]。类型 #cf_span[1] 的关系表示子物体是父物体的一个特例。类型 #cf_span[2] 的关系表示第二个物体 *总是* 是第一个物体及其所有特例的一部分。\n\n注意，如果物体 #cf_span[b] 是物体 #cf_span[a] 的特例，且 #cf_span[c] 是物体 #cf_span[b] 的特例，则 #cf_span[c] 也被视为物体 #cf_span[a] 的特例。同样适用于部分关系：如果物体 #cf_span[b] 是 #cf_span[a] 的一部分，且物体 #cf_span[c] 是 #cf_span[b] 的一部分，则我们称物体 #cf_span[c] 是 #cf_span[a] 的一部分。此外，如果物体 #cf_span[b] 是 #cf_span[a] 的一部分，且物体 #cf_span[c] 是 #cf_span[a] 的特例，则 #cf_span[b] 也是 #cf_span[c] 的一部分。\n\n一个物体不被视为其自身的部分或其自身的特例。\n\n现在，哈利需要回答两种类型的查询：\n\n输入的第一行包含物体数量 #cf_span[n]（#cf_span[1 ≤ n ≤ 10^5]）。\n\n接下来的 #cf_span[n] 行每行包含两个整数 #cf_span[parenti] 和 #cf_span[typei]（#cf_span[ - 1 ≤ parenti < i]，#cf_span[parenti ≠ 0]，#cf_span[ - 1 ≤ typei ≤ 1]），表示第 #cf_span[i] 个物体的父物体是 #cf_span[parenti]。（若 #cf_span[typei = 0]，表示物体 #cf_span[i] 是物体 #cf_span[parenti] 的特例；若 #cf_span[typei = 1]，表示物体 #cf_span[i] 是物体 #cf_span[parenti] 的一部分）。若第 #cf_span[i] 个物体没有父物体，则 #cf_span[parenti] 和 #cf_span[typei] 均为 _-1_。\n\n下一行包含一个整数 #cf_span[q]（#cf_span[1 ≤ q ≤ 10^5]），表示查询数量。\n\n接下来的 #cf_span[q] 行每行包含三个用空格分隔的整数 #cf_span[typei, ui, vi]（#cf_span[1 ≤ typei ≤ 2，1 ≤ u, v ≤ n]）。\n\n输出将包含 #cf_span[q] 行，每行对应一个查询的答案，输出为 \"_YES_\"（肯定）或 \"_NO_\"（不含引号）。\n\n你可以以任意大小写输出每个字母。\n\n在测试用例 #cf_span[1] 中，由于物体 #cf_span[2] 是物体 #cf_span[1] 的特例，且物体 #cf_span[3] 是物体 #cf_span[2] 的特例，因此物体 #cf_span[3] 是物体 #cf_span[1] 的特例。\n\n在测试用例 #cf_span[2] 中，由于物体 #cf_span[2] 是物体 #cf_span[1] 的特例，且物体 #cf_span[1] 包含物体 #cf_span[3]，这意味着物体 #cf_span[2] 也会包含物体 #cf_span[3]。这是因为当一个一般情况（物体 #cf_span[1]）包含物体 #cf_span[3] 时，它的特例（物体 #cf_span[2]）必定也包含物体 #cf_span[3]。"},{"iden":"input","content":"输入的第一行包含物体数量 #cf_span[n]（#cf_span[1 ≤ n ≤ 10^5]）。接下来的 #cf_span[n] 行每行包含两个整数 #cf_span[parenti] 和 #cf_span[typei]（#cf_span[ - 1 ≤ parenti < i]，#cf_span[parenti ≠ 0]，#cf_span[ - 1 ≤ typei ≤ 1]），表示第 #cf_span[i] 个物体的父物体是 #cf_span[parenti]。（若 #cf_span[typei = 0]，表示物体 #cf_span[i] 是物体 #cf_span[parenti] 的特例；若 #cf_span[typei = 1]，表示物体 #cf_span[i] 是物体 #cf_span[parenti] 的一部分）。若第 #cf_span[i] 个物体没有父物体，则 #cf_span[parenti] 和 #cf_span[typei] 均为 _-1_。下一行包含一个整数 #cf_span[q]（#cf_span[1 ≤ q ≤ 10^5]），表示查询数量。接下来的 #cf_span[q] 行每行包含三个用空格分隔的整数 #cf_span[typei, ui, vi]（#cf_span[1 ≤ typei ≤ 2，1 ≤ u, v ≤ n]）。"},{"iden":"output","content":"输出将包含 #cf_span[q] 行，每行对应一个查询的答案，输出为 \"_YES_\"（肯定）或 \"_NO_\"（不含引号）。你可以以任意大小写输出每个字母。"},{"iden":"examples","content":"输入\n3\n-1 -1\n1 0\n2 0\n2\n1 1 3\n2 1 3\n输出\nYES\nNO\n\n输入\n3\n-1 -1\n1 0\n1 1\n2\n2 2 3\n2 3 2\n输出\nYES\nNO"},{"iden":"note","content":"在测试用例 #cf_span[1] 中，由于物体 #cf_span[2] 是物体 #cf_span[1] 的特例，且物体 #cf_span[3] 是物体 #cf_span[2] 的特例，因此物体 #cf_span[3] 是物体 #cf_span[1] 的特例。\n\n在测试用例 #cf_span[2] 中，由于物体 #cf_span[2] 是物体 #cf_span[1] 的特例，且物体 #cf_span[1] 包含物体 #cf_span[3]，这意味着物体 #cf_span[2] 也会包含物体 #cf_span[3]。这是因为当一个一般情况（物体 #cf_span[1]）包含物体 #cf_span[3] 时，它的特例（物体 #cf_span[2]）必定也包含物体 #cf_span[3]。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of objects, numbered $ 1 $ to $ n $.  \nFor each object $ i \\in \\{1, \\dots, n\\} $, define:  \n- $ p_i \\in \\{-1\\} \\cup \\{1, \\dots, i-1\\} $: the parent of object $ i $, or $-1$ if none.  \n- $ t_i \\in \\{0, 1\\} $: the type of parent relation, where  \n  - $ t_i = 0 $ means $ i $ is a *special case* of $ p_i $,  \n  - $ t_i = 1 $ means $ i $ is a *part* of $ p_i $.  \n\nDefine two binary relations $ \\prec_s $ (special case) and $ \\prec_p $ (part-of) on $ \\{1, \\dots, n\\} $:  \n- $ i \\prec_s j $ iff there exists a directed path from $ i $ to $ j $ using only edges with $ t_k = 0 $.  \n- $ i \\prec_p j $ iff there exists a directed path from $ i $ to $ j $ using only edges with $ t_k = 1 $.  \n\nExtend these relations transitively and consistently with the rules:  \n1. $ \\prec_s $ and $ \\prec_p $ are transitive.  \n2. If $ a \\prec_p b $ and $ b \\prec_s c $, then $ a \\prec_p c $.  \n3. If $ a \\prec_s b $ and $ b \\prec_p c $, then $ a \\prec_p c $.  \n4. No object is related to itself under $ \\prec_s $ or $ \\prec_p $.  \n\n**Constraints**  \n1. $ 1 \\leq n \\leq 10^5 $  \n2. $ 1 \\leq q \\leq 10^5 $  \n3. For each query: $ \\text{type}_i \\in \\{1,2\\} $, $ u,v \\in \\{1,\\dots,n\\} $, $ u \\ne v $\n\n**Objective**  \nFor each query $ (\\text{type}, u, v) $:  \n- If $ \\text{type} = 1 $, output \"YES\" if $ u \\prec_s v $, else \"NO\".  \n- If $ \\text{type} = 2 $, output \"YES\" if $ u \\prec_p v $, else \"NO\".","simple_statement":null,"has_page_source":false}