Poke Problem

View as PDF

Points: 7
Time limit: 0.6s
Memory limit: 64M

Authors:
Problem type
Allowed languages
C, C++

Due to the recent Pokemon games that came out, Sun and Moon, we might as well create a problem based off it.

Given the effectiveness of certain types over another, and the typing of the Pokemon, determine which type would be the most effective against the Pokemon.

Input

The first line of input includes 2 integers, , the number of types, and .

The next lines show you which types are effective against which, as denoted by integers and , where " is super effective against " and as such " is not effective against ". (As a side note, the types are depicted through numbers to , and if a type is not explicitly shown to be super or not effective against another type, it's considered neutral).

The next line shows you the number of types the Pokemon has.

The following line shows the type(s) of that Pokemon (a Pokemon can only have either one or two types).

Output

The output will consist of one number which is the type that the Pokemon is weakest against.

• A type that is super effective against both of the Pokemon's types is better than a type that is super effective against only one of the types.
• If a type is super effective against one of the types of the Pokemon, but is not effective against the other, it is considered neutral.
• If none of the types are super effective against the Pokemon (That is, all the types are not effective or do neutral damage to the Pokemon), then output .
• If one type has the same effectiveness against the Pokemon as another type, output the smaller/smallest number.

Subtask 2 (): As per sample testcases.

Sample Input 1

4 3
1 2
2 3
3 4
2
3 4

Sample Output 1

2

Sample Input 2

3 2
2 1
3 2
2
1 3

Sample Output 2

0