#P1477. [NOI2008] 假面舞会
[NOI2008] 假面舞会
Description
The annual masquerade has begun, and Dongdong is excited to attend this year’s party.
This year’s masks are specially made by the organizers. Each participant can choose a mask they like upon entry. Every mask has an ID number, and the organizer tells the wearer that number.
To add mystery, the organizer divides masks into classes (). Using special techniques, the number of each mask is marked so that only people wearing a class mask can see the numbers of people wearing class masks, and people wearing class masks can see the numbers of people wearing class masks.
Participants do not know how many classes there are, but Dongdong is very curious and wants to figure it out himself, so he starts collecting information from the crowd.
The information Dongdong collects is of the form: “the wearer of mask number saw the number of mask .” For example, the wearer of mask saw the number of mask . Dongdong also sees some numbers himself, and he adds the corresponding information using his own mask number.
Since not everyone can remember all the numbers they saw, Dongdong’s collected information may be incomplete. Please compute, based on the information Dongdong currently has, the maximum and the minimum possible numbers of mask classes. Since the organizer has declared , you must also take this into account.
Input Format
The first line contains two integers , separated by a space, where is the total number of masks prepared by the organizer, and is the number of pieces of information Dongdong collected. The next lines each contain two integers separated by a space, meaning the wearer of mask saw the number of mask . The same pair may appear multiple times in the input.
Output Format
Output two numbers: the first is the maximum possible number of mask classes, and the second is the minimum possible number of mask classes. If it is impossible to partition all masks into at least classes so that all the information is satisfied, print two -1.
6 5
1 2
2 3
3 4
4 1
3 5
4 4
3 3
1 2
2 1
2 3
-1 -1
Hint
- For of the testdata, , .
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号