Problem C
Horror List

However, it turned out that some people were extremely disappointed, because they got to see movies like Ghosts of Mars, which instead caused them to tear out their hair in despair and horror.
To avoid this problem for the next convention, Ian has come up with a solution, but he needs your help to implement it. When the group enters the surprise room, they will type in a list of movies in a computer. This is the so-called horror list, which consists of bad movies that no one in the group would ever like to see. Of course, this list varies from group to group.
You also have access to the database Awesome Comparison of Movies which tells you which movies are directly similar to which. You can assume that movies that are similar to bad movies will be almost as bad. More specificly, we define the Horror index as follows:
Input
The first line of input contains three positive integers
The second line contains
The following
Output
Output the ID of the movie in the collection with the highest Horror Index. In case of a tie, output the movie with the lowest ID.
Sample Input 1 | Sample Output 1 |
---|---|
6 3 5 0 5 2 0 1 1 2 4 5 3 5 0 2 |
1 |
Sample Input 2 | Sample Output 2 |
---|---|
6 2 3 5 2 0 5 0 1 3 4 |
3 |