eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Find the Treasure

Find the Treasure

Four hundred years ago, a group of pirates hid a treasure on an island in an archipelago that consists of many very small islands. Unfortunately, these pirates were particularly bad navigators and cartographers. Therefore, instead of a map, they made drawings of views from the top of the mountain on the treasure island. Each view shows two or more other islands of the archipelago that can be seen from the treasure island, ordered from left to right. The views also contain lots of fog, so the drawings may fail to show some islands that must have been in the field of view between the islands that appear in the drawing. For example, in \textit{Figure 1} below, if the treasure is hidden on Rummet, then the pirates could have drawn a view showing (from left to right) Wisket, Ginnet and Vinnet, or a view showing (from left to right) Liquorel and Cidrel. The pirates are known to have had acute vision, with a viewing angle of \textbf{180} degrees, but bad drawing skills: the distances between Wisket, Ginnet and Vinnet in their drawing are meaningless, and Liquorel may be drawn far to the left of Cidrel while in the actual view from Rummet, Liquorel must have been only slightly to the left of Cidrel, even obscuring part of it. Fortunately, all islands in the drawings can be identi ed easily thanks to the unique towers on top of each island. \includegraphics{https://static.e-olymp.com/content/51/51f1d4058a791f2fcbf62c744c79b512d4cd00b6.jpg} \textit{Figure 1}. Map of hypothetical archipelago, and some views from Rummet as the pirates could have drawn them. Now, four hundred years later, you have got the pirates' drawings and an excellent, accurate map of the archipelago, showing all islands. On which island is the treasure hidden? \InputFile The first line of the input contains a single number: the number of archipelagos to follow. Each archipelago has the following format: \begin{itemize} \item One line with an integer \textbf{n}, satisfying \textbf{1} ≤ \textbf{n} ≤ \textbf{125,000}: the number of islands in the archipelago. \item \textbf{n} lines, each with two integers \textbf{x_i} and \textbf{y_i}, satisfying \textbf{0} < \textbf{x_i} < \textbf{2^29} and \textbf{0} < \textbf{y_i} < \textbf{2^29}: these are the coordinates of the tower \textbf{T_i} on each island. \item One line with an integer \textbf{k}: the number of test cases for this archipelago. Each test case hasthe following format: \begin{itemize} \item One line with an integer \textbf{m}, satisfying \textbf{0} ≤ \textbf{m} ≤ \textbf{10,000}: the number of pairs of islands that appear in the pirates' drawings. \item \textbf{m} lines, each with two integers \textbf{l} and \textbf{r} such that \textbf{1} ≤ \textbf{l} ≤ \textbf{n}, \textbf{1} ≤ \textbf{r} ≤ \textbf{n}, \textbf{l} ≠ \textbf{r}, meaning that the tower \textbf{T_l} is drawn to the left of tower \textbf{T_r}. \end{itemize} \end{itemize} \textbf{Ouput} For every test case in the input, the output should contain: \begin{itemize} \item One line with an integer \textbf{i} (\textbf{1} ≤ \textbf{i} ≤ \textbf{n}), identifying the \textbf{i}-th island in the archipelago, for each island that could be the treasure island. These lines need to be in increasing order. \item One line containing the number \textbf{0}. \end{itemize} \textbf{Example} The following input describes one archipelago with one test case, namely the information corre-sponding to the map and the views shown in \textit{Figure 1}. The potential treasure islands are Rummet, Alet, and Schnahpsum.
Лимит времени 2 секунды
Лимит использования памяти 32 MiB
Входные данные #1
1
9
28 34
32 30
12 29
27 22
42 23
18 18
5 14
26 12
34 5
1
4
1 2
1 9
2 9
4 5
Выходные данные #1
6
7
8
0
Источник ICPC BAPC 2011 Finals