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

Rankings

Rankings

There are \textbf{n} teams (labelled from \textbf{1} to \textbf{n}) who take part in a programming competition every year, and at the end they are ranked in order of merit. The rankings for last year are known. This year, the jury wants to make the event less competitive, and decides not to publish such a ranking list (since teams near the bottom might get disheartened). Instead, they will produce a complete list of pairs of teams whose relative rank order has changed from last year to this year. For example, if team \textbf{13} placed above team \textbf{6} last year, but team 6 placed above team \textbf{13} this year, the pair (\textbf{6}, \textbf{13}) is announced. This would enable teams to track their progress against a particular opposing team, but not give them a clear sense of where they stand overall. Of course, this isn't going to stop your team from trying to determine the overall ranking list. Given last year's rankings and a complete list of the pairs of teams whose relative rank order has changed, reconstruct as much of this year's standings as possible. It is possible that the jury might have made an error, so if the data given is inconsistent with any possible ranking list for this year, you should also detect this. \InputFile On the first line a positive integer: the number of test cases, at most \textbf{100}. After that per test case: \begin{itemize} \item One line with an integer \textbf{n} (\textbf{2} ≤ \textbf{n} ≤ \textbf{500}): the number of teams. \item One line with \textbf{n} integers \textbf{t_i} (\textbf{1} ≤ \textbf{t_i} ≤ _n): the rankings for last year, from best team to worst team. \textbf{t_i} represents the team who came in position \textbf{i} (\textbf{1}-indexed) on the ranklist. All the ti will be distinct. \item One line with an integer \textbf{m} (\textbf{0} ≤ \textbf{m} ≤ \textbf{25 000}): the number of pairs whose relative rank order has changed. \item \textbf{m} lines with two integers \textbf{a_i} and \textbf{b_i} (\textbf{1} ≤ \textbf{a_i} < \textbf{b_i} ≤ \textbf{n}) each: a pair of teams whose relative rank order has changed. Each such pair will be mentioned exactly once. \end{itemize} \OutputFile Per test case: \begin{itemize} \item One line with \textbf{n} integers: the rankings for this year, from best to worst, where the \textbf{i}-th term (\textbf{1}-indexed) represents the team in position \textbf{i}. If this team cannot be determined with certainty, the integer should be replaced with a '\textbf{?}' character. If the data for a particular test case is inconsistent with any possible ranking list for this year, the line must contain "\textbf{IMPOSSIBLE}" instead. \end{itemize}
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
3
5
5 4 3 2 1
2
2 4
3 4
3
2 3 1
0
4
1 2 3 4
3
1 2
3 4
2 3
Выходные данные #1
5 3 2 4 1
2 3 1
IMPOSSIBLE
Источник NWERC-2010