#P15636. [2019 KAIST RUN Spring] Jealous Teachers
[2019 KAIST RUN Spring] Jealous Teachers
题目描述
There are teachers and students in the Seoul Science High School. Each student bought flowers because tomorrow is a teacher's day in Korea. However, one of the students quit, and now only students remain in the school.
Teachers are very jealous, so they will give an F grade to students when they receive fewer flowers from that student than others. Therefore, every teacher should receive exactly flowers. A student can only give flowers to teachers who have taught him or her, and you know which students have learned from which teachers.
Younghun is the student of Seoul Science High School, and he needs your help in organizing this event.
输入格式
The first line contains two integers and (, ) describing the number of teachers and the number of (student, teacher) pairs where the student learned from the teacher.
In the next lines describe the relations: -th line contains two integers , (, ) indicating that -th student can give flowers to the -th teacher. It is guaranteed that all pairs are different.
输出格式
If it is impossible to give all teachers the same number of flowers ( flowers), print a single number in the first line.
Otherwise, your program should output lines. In -th line, there should be a single integer denoting the number of flowers which -th student gave to -th teacher.
If there are multiple possible answers, you can output any of them.
6 12
1 3
1 4
1 5
2 2
2 4
3 1
3 3
4 1
4 2
4 4
5 4
5 6
1
0
5
5
1
2
4
3
0
3
1
5
6 12
1 2
1 3
1 4
2 2
2 4
3 1
3 3
4 1
4 2
4 4
5 5
5 6
-1