PivotOJ

Naboj

시간 제한: 1000ms메모리 제한: 512MB출처: COCI 2021-2022BOJ 25041

문제

Mr. Šikić, a chemistry teacher, is playing around with nn metal balls and mm 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 nn and mm (1 ≤ n ≤ 200\,000, 1 ≤ m ≤ 500\,000) from the task statement.

The following mm lines contain integers aia_i and bib_i (1 ≤ a_i , b_i ≤ n, aibia_i \ne b_i) denoting that the balls aia_i and bib_i are connected by a wire and the electrons in the wire should be closer to aia_i, and not bib_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-1. Otherwise print kk, the required number of ball chargings. kk must be less than or equal 200000200\,000.

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

힌트

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.

예제

예제 1

입력
3 3
1 2
2 3
1 3
출력
3
2 1
3 0
1 1

예제 2

입력
4 3
1 2
3 2
2 4
출력
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
출력
-1
코드를 제출하려면 로그인하세요.