#P3530. [POI 2012] FES-Festival
[POI 2012] FES-Festival
Description
You do not know the results of the race, but Byteasar will tell you partial information. Now, you are asked to answer: what is the maximum number of distinct finishing times that all participants can have without violating his conditions? Some of them may tie (i.e., finish at the same time), and such ties count as one distinct time.
Byteasar tells you that all finishing times are integer seconds. He will also provide some relations between the participants’ times. Specifically, he will give you some pairs , meaning that ’s time is exactly second less than ’s; and some pairs , meaning that ’s time is not greater than ’s. Your task is to compute the maximum possible number of distinct finishing times for all participants that satisfies these conditions.
Please write a program to solve this puzzle.
Input Format
The first line contains three integers , denoting the number of participants, the number of pairs , and the number of pairs , respectively.
The next lines each contain two integers (). This means participant ’s time is exactly second less than participant ’s.
The next lines each contain two integers (). This means participant ’s time is not greater than participant ’s.
Output Format
If there is a solution, output a single integer on one line, representing the maximum number of distinct finishing times among all participants.
If there is no solution, output NIE.
4 2 2
1 2
3 4
1 4
3 1
3
Hint
The answer is , with , , .
( denotes the time spent by participant .)
Constraints
- For of the testdata, .
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号