Poke Problem

View as PDF

Submit solution

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

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.


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

The next C lines show you which types are effective against which, as denoted by integers A and B, where "A is super effective against B" and as such "B is not effective against A". (As a side note, the types are depicted through numbers 1 to N, 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).


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

Please note the following:

  • 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 0.
  • If one type has the same effectiveness against the Pokemon as another type, output the smaller/smallest number.


Subtask 1 (100\%): 2 \le N \le 100, 1 \le C \le 100.

Subtask 2 (0\%): As per sample testcases.

Sample Input 1

4 3
1 2
2 3
3 4
3 4

Sample Output 1


Sample Input 2

3 2
2 1
3 2
1 3

Sample Output 2



There are no comments at the moment.