In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
A charity festival is taking place in Byteburg, and you are one of the fundraisers. Unfortunately you have missed some fun activities, including a steeplechase. Byteasar, an amateur of puzzles, has promised a big donation if you manage to solve his riddle.
You do not know the results of the steeplechase but Byteasar has provided you with partial information. Now he is asking you what is the maximum possible (consistent with what he has told you) number of different times attained by the runners (some of them may have tied, i.e., reached the finish at the same time). Byteasar has told you that every runner's time is an integer multiple of one second. He has also provided you with relations between some of the runners' times. Specifically, he has given you some of the pairs of runners for which 's time was exactly one second smaller than 's time, and some of the pairs of runners for which 's time was no larger than 's time. Write a program that will solve the riddle for you!
The first line of the standard input contains three non-negative integers, , , (, ), separated by single spaces, that denote respectively: the number of runners, the number of revealed pairs of the first type , and the number of revealed pairs of the second type . The runners are numbered from 1 to .
In the following lines the pairs of runners of the first kind are given, one per line - the -th such line holds two integers and , , separated by a single space, that denote that runner 's time was exactly one second smaller than 's.
In the next lines the pairs of runners of the second kind are given, one per line - the -th such line holds two integers and , , separated by a single space, that denote that runner 's time was no larger than 's.
In the first and only line of the standard output your program should print a single integer equal to the maximum possible number of different times attained by the runners consistent with the criteria.
If there is no order of runners satisfying Byteasar's constraints, the program should output a single line holding the word "NIE" (Polish for no), without the quotation marks.
In tests worth at least 15% of points it additionally holds that .
For the input data:
4 2 2 1 2 3 4 1 4 3 1
the correct result is:
3
Explanation of the example: There were two possible outcomes of the chase:
Task author: Marian M. Kedzierski.