logo AlgoBeat OnlineJudge
登录 注册

#215698. [2019 KAIST RUN Spring] Jealous Teachers

内存限制:1024 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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.

样例

样例输入 1

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

1
0
5
5
1
2
4
3
0
3
1
5

样例输入 2

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

样例输出 2

-1