{"raw_statement":[{"iden":"statement","content":"GEMA is hosting Q rounds of 10-hour-long contests in honor of the great Danfto. Everybody wants to honor Danfto, but 10 hours is a really long time, so people are wondering whether to go or not.\n\nA person's decision is affected by their best friend's decision. Each person has at most one best friend and there are no cycles (this is not a Disney movie and there are no reciprocated friendships), meaning that if Nicoleta's best friend is Sancho and Sancho's best friend is Teoo, Teoo's best friend is not Sancho nor Nicoleta. In this case, Nicoleta will participate only if Sancho does, Sancho will participate only if Teoo does, and Teoo doesn't have a best friend so he doesn't depend on anyone.\n\nPeople can also depend on some other factors like the weather, their mood or their mothers' permission. So there's no guarantee that they will participate even if their best friend does.\n\nNow the rounds have passed and you are very curious about who were the brave souls that went to each round. You asked Tomaso if Teoo participated in a round, but Tomaso was drunk, so instead of replying yes or no, he told you that Nicoleta participated. You can deduce that Teoo went to the contest too because Nicoleta would only participate if Sancho did, which in turn would only go if Teoo did.\n\nYou asked Tomaso Q questions, one for each round, of whether y participated, and he told you that x did. Is it possible to know for sure if y participated in the round given that x did?\n\nThe first line of the input contains two integers, N (2 ≤ N ≤ 1 × 105) and Q (1 ≤ Q ≤ 2 × 105), indicating the number of people invited to the Danfto honor rounds and the number of questions you asked Tomaso.\n\nThe next line contains N integers. The i-th integer ai (ai =  - 1 or 0 ≤ ai ≤ N - 1) indicates that the i-th person will only participate in a round if the ai-th person does. If a person doesn't depend on anyone, ai is -1.\n\nQ lines follow. The j-th line contains two integers xj and yj (0 ≤ xj, yj ≤ N - 1) indicating that you want to know if the yj-th person participated in the j-th round, and Tomaso told you that the xj-th person did.\n\nFor each query, output \"Yes\" if you can determine that the y-th person participated and output \"No\" otherwise.\n\n"},{"iden":"input","content":"The first line of the input contains two integers, N (2 ≤ N ≤ 1 × 105) and Q (1 ≤ Q ≤ 2 × 105), indicating the number of people invited to the Danfto honor rounds and the number of questions you asked Tomaso.The next line contains N integers. The i-th integer ai (ai =  - 1 or 0 ≤ ai ≤ N - 1) indicates that the i-th person will only participate in a round if the ai-th person does. If a person doesn't depend on anyone, ai is -1.Q lines follow. The j-th line contains two integers xj and yj (0 ≤ xj, yj ≤ N - 1) indicating that you want to know if the yj-th person participated in the j-th round, and Tomaso told you that the xj-th person did."},{"iden":"output","content":"For each query, output \"Yes\" if you can determine that the y-th person participated and output \"No\" otherwise."}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $ be the number of boats, labeled $ 1, 2, \\dots, N $ (smallest to largest).  \nLet $ K \\in \\mathbb{Z}^+ $ be the total number of allowed trips.  \nThree stacks represent ports:  \n- $ P $: Portugal (initially contains $ [1, 2, \\dots, N] $, top = 1),  \n- $ C $: China (initially empty),  \n- $ E $: England (initially empty).  \n\nA trip moves the top element (smallest remaining boat) from one stack to another, subject to:  \n1. **Stack constraint**: A boat $ b $ may only be placed on top of a stack if the current top element (if any) is larger than $ b $.  \n\n**Constraints**  \n1. $ 1 \\leq N \\leq 100 $  \n2. $ 1 \\leq K \\leq 1000 $  \n\n**Objective**  \nDetermine if it is possible to transfer all $ N $ boats from $ P $ to $ E $ in exactly $ K $ trips, obeying the stack constraint.  \nIf possible, output:  \n- First line: `\"Y\"`  \n- Next $ K $ lines: each line is a trip `\"X Y\"` where $ X, Y \\in \\{P, C, E\\} $, representing a move from stack $ X $ to stack $ Y $.  \nIf impossible, output:  \n- First line: `\"N\"`","simple_statement":"Given N boats and K trips, can you move all N boats from Portugal to England using three ports (Portugal, China, England) with stack rules? If yes, output \"Y\" and show K trips; otherwise, output \"N\".","has_page_source":false}