시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB52240.000%

문제

Mr. Šikić, a chemistry teacher, is playing around with $n$ metal balls and $m$ copper wires. He joined together some pairs of balls with a wire so that all the balls are (directly or indirectly) linked to each other. He wants to teach his students about electric charge so he’ll demonstrate it by charging the metal balls in a sequence.

Mr Šikić can either charge each of the balls positively or negatively. When a ball is charged negatively, the electrons in all the wires connected to the ball are repulsed to the other ball connected to that wire. Conversely, if a ball is positively charged, the electrons from all the wires connected to that ball are pulled towards it. Charging the balls has the same effect on the wires irrespective of the wire’s previous state.

At the beginning of the class all the balls hold no charge and the electrons in all the wires are still. For every wire Mr. Šikić has a specific direction of the electron flow in mind. Help him find a sequence of ball chargings that results in the desired electron flows.

입력

The first line contains two integers $n$ and $m$ ($1 ≤ n ≤ 200\,000$, $1 ≤ m ≤ 500\,000$) from the task statement.

The following $m$ lines contain integers $a_i$ and $b_i$ ($1 ≤ a_i , b_i ≤ n$, $a_i \ne b_i$) denoting that the balls $a_i$ and $b_i$ are connected by a wire and the electrons in the wire should be closer to $a_i$, and not $b_i$. There is at most one wire between a pair of balls. All the balls are directly or indirectly connected by wires.

출력

If it is impossible to direct the flow of electrons according to Mr. Šikić’s wishes print $-1$. Otherwise print $k$, the required number of ball chargings. $k$ must be less than or equal $200\,000$.

In the following $k$ lines print integers $c_i$ and $d_i$ ($1 ≤ c_i ≤ n$, $0 ≤ d_i ≤ 1$), the number of the ball Mr. Šikić should charge in $i$-th step and whether it should be charged positively (denoted by $d_i = 1$) or negatively ($d_i = 0$). If there are multiple solutions, print any one of them.

서브태스크

번호배점제한
115

$1 ≤ n ≤ 10$

225

$m = n - 1$

370

No additional constraints.

예제 입력 1

3 3
1 2
2 3
1 3

예제 출력 1

3
2 1
3 0
1 1

예제 입력 2

4 3
1 2
3 2
2 4

예제 출력 2

4
2 1
4 0
3 1
1 1

예제 입력 3

5 10
2 4
3 4
1 4
4 5
3 2
2 1
5 2
1 3
5 3
1 5

예제 출력 3

-1

힌트

Clarification of the first example:

First, we give the ball 2 a positive charge. The electrons on wires between balls 1 and 2, and balls 2 and 3 are now closer to the ball 2. The wire connecting balls 1 and 3 remains neutral.

Now we give ball 3 a negative change. The arrangement of electrons between wires 2 and 3 remains unchanged, while the electrons on the wire between 1 and 3 are closer to the ball 1.

Finally we give ball 1 a positive charge. The wire between 1 and 3 remains unchanged, but on the wire between balls 1 i 2 electrons are now closer to the ball 1 and the desired arrangement is achieved.

채점 및 기타 정보

  • 예제는 채점하지 않는다.