eolymp
bolt
Try our new interface for solving problems
Məsələlər

Game Rigging

Game Rigging

You've decided to host a StarCraft II tournament to decide who is the very best StarCraft II player at Stanford. A lot of your friends are entering, and you want one of them to win because the prize is two tickets to the next StarCraft II World Finals! Luckily, you get to arrange the games and you have some information about which players will beat which other ones, i.e. match-ups which have a guaranteed outcome. The tournament is played as a series of games where in each game two players (of your choice) who have not yet been eliminated play each other. This continues until only one player remains, and he is the winner. Can you set the tournament up so that one of your friends wins? \InputFile The input consists of multiple test cases. Each test case will start with two integers \textbf{N} (\textbf{2} ≤ \textbf{N} ≤ \textbf{100000}), the number of players in the tournament, \textbf{K} (\textbf{1} ≤ \textbf{K} ≤ \textbf{N}), the number of your friends in the tournament, and \textbf{M} (\textbf{0} ≤ \textbf{M} ≤ \textbf{100000}), the number of match-ups for which you know the outcome. The next line will contain \textbf{K} integers between \textbf{1} and \textbf{N}, indicating which of the players are your friends (indices corresponding to the order of the input). The following \textbf{M} lines will contain two integers each; a line containing \textbf{A} \textbf{B} indicates that if players \textbf{A} and \textbf{B} play each other, player \textbf{A} will always beat player \textbf{B}. Input is followed by a single line with \textbf{N = K = 0}, which should not be processed. \OutputFile For each test case, output one line which contains either "\textbf{yes}" or "\textbf{no}" (without quotes) indicating whether you can guarantee that one of your friends wins the tournament.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
4 1 3
1
1 2
1 3
2 4
0 0 0
Çıxış verilənləri #1
yes