{"trustable":true,"prependHtml":"\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eOnce in a forest, there lived N aggressive monkeys.\nAt the beginning, they each does things in its own way and none of them knows each other.\nBut monkeys can\u0027t avoid quarrelling, and it only happens between two monkeys who does not know each other.\nAnd when it happens, both the two monkeys will invite the strongest friend of them, and duel.\nOf course, after the duel, the two monkeys and all of their friends knows each other, and the quarrel above will no longer happens between these monkeys even if they have ever conflicted.\u003c/p\u003e\n\n\u003cp\u003eAssume that every money has a strongness value, which will be reduced to only half of the original after a duel(that is, 10 will be reduced to 5 and 5 will be reduced to 2).\u003c/p\u003e\n\n\u003cp\u003eAnd we also assume that every monkey knows himself. That is, when he is the strongest one in all of his friends, he himself will go to duel.\u003c/p\u003e\n\n\u003cbr\u003e\n\u003cb\u003e\u003cp\u003eInput\u003c/p\u003e\u003c/b\u003e\n\u003cp\u003eThere are several test cases, and each case consists of two parts.\u003c/p\u003e\n\u003cp\u003eFirst part: The first line contains an integer N(N\u0026lt;\u003d100,000), which indicates the number of monkeys. And then N lines follows. There is one number on each line, indicating the strongness value of ith monkey(\u0026lt;\u003d32768).\u003c/p\u003e\n\u003cp\u003eSecond part: The first line contains an integer M(M\u0026lt;\u003d100,000), which indicates there are M conflicts happened. And then M lines follows, each line of which contains two integers x and y, indicating that there is a conflict between the Xth monkey and Yth.\u003c/p\u003e\n\n\u003cbr\u003e\n\u003cp\u003e\u003cb\u003eOutput\u003c/b\u003e\u003c/p\u003e\n\n\u003cp\u003eFor each of the conflict, output -1 if the two monkeys know each other, otherwise output the strongness value of the strongest monkey in all friends of them after the duel.\u003c/p\u003e\n\n\n\u003cb\u003e\u003cp\u003eSample Input\u003c/p\u003e\u003c/b\u003e\n\u003cp\u003e\n5\u003cbr\u003e\n20\u003cbr\u003e\n16\u003cbr\u003e\n10\u003cbr\u003e\n10\u003cbr\u003e\n4\u003cbr\u003e\n5\u003cbr\u003e\n2 3\u003cbr\u003e\n3 4\u003cbr\u003e\n3 5\u003cbr\u003e\n4 5\u003cbr\u003e\n1 5\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\u003cb\u003eSample Output\u003c/b\u003e\u003c/p\u003e\n\u003cp\u003e\n8\u003cbr\u003e\n5\u003cbr\u003e\n5\u003cbr\u003e\n-1\u003cbr\u003e\n10\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\u003cbr\u003e\n\u003c/p\u003e\n"}}]}