{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"Boatherds Inc. is a sailing company operating in the country of Trabantustan and offering boat trips on Trabantian rivers. All the rivers originate somewhere in the mountains and on their way down to the lowlands they gradually join and finally the single resulting river flows to the sea. Moreover, the Trabantian villages are exactly at the rivers\u0027 springs, junctions and at the mouth of the largest river. Please note that more than 2 rivers can join at a junction. However, the rivers always form a tree (with villages as vertices). \r\u003cbr\u003e\r\u003cbr\u003eThe pricing policy of the Boatherds is very simple: each segment of each river between two villages is assigned a price (the price is same in both directions), so if a tourist requests a journey between any two villages, the ticket office clerks just add the prices of the segments along the only path between the villages. \r\u003cbr\u003e\r\u003cbr\u003eOne day, a very strange tourist appeared. She told the clerks that she returns to her country on the next day and she wants to spend all the remaining money on a boat trip, so they should find a route with exactly this cost. Being just poor (ahem) businessmen, they have asked the Abacus Calculator Makers for help. \r\u003cbr\u003e\r\u003cbr\u003eYou are given a description of the river network with costs of river segments and a sequence of integers x1,..., xk. For each xi, you should determine if there is a pair of cities (a, b) in the river network such that the cost of the trip between a and b is exactly xi.\r\u003cbr\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input consists of several instances. Each instance is described by (in the following order): \r\u003cbr\u003e\u003cul\u003e\u003cli\u003eA single line containing a single integer: the number of villages N (1 \u0026lt;\u003d N \u0026lt;\u003d 10 000). \r\u003cbr\u003e\u003c/li\u003e\u003cli\u003eN lines describing the villages. The i-th of these lines (1 \u0026lt;\u003d i \u0026lt;\u003d N) describes the village with number i. It contains space separated integers d1, c1, d2, c2, , d\u003csub\u003eki\u003c/sub\u003e, c\u003csub\u003eki\u003c/sub\u003e, 0. The dj\u0027s are numbers of villages from which the rivers flow directly to the village i (with no other villages in between), each cj is the price of the journey between villages i and dj. Moreover, 2 \u0026lt;\u003d dj \u0026lt;\u003d N and 0 \u0026lt;\u003d cj \u0026lt;\u003d 1 000. Village 1 always corresponds to the mouth of the largest river, therefore no di can ever be equal to 1. \r\u003cbr\u003e\u003c/li\u003e\u003cli\u003eM \u0026lt;\u003d 100 lines describing the queries. The i-th of these lines corresponds to the i-th query and contains a single integer xi (1 \u0026lt;\u003d xi \u0026lt;\u003d 10 000 000). \r\u003cbr\u003e\u003c/li\u003e\u003cli\u003eThe instance is finished by a single line containing the number 0. \u003c/li\u003e\u003c/ul\u003e\r\u003cbr\u003eThe whole input is ended by a single line containing the number 0.\r\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each instance you should produce a sequence of M lines (where M is the number of queries in the particular instance). The i-th of these lines contains the word \"AYE\" if there exists a pair of cities in the river network which is connected by a path of cost xi, or the word \"NAY\" otherwise. \r\u003cbr\u003e\r\u003cbr\u003eOutput for each instance must be followed by a single line containing just the dot character.\r\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e6\r\n2 5 3 7 4 1 0\r\n0\r\n5 2 6 3 0\r\n0\r\n0\r\n0\r\n1\r\n8\r\n13\r\n14\r\n0\r\n0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eAYE\r\nAYE\r\nNAY\r\nAYE\r\n.\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}