Hypercatapult Commute

시간 제한3초메모리 제한2048 MB

요약
모든 승객이 하루 동안 공유 발사 일정을 이용해 출발 도시에서 도착 도시로 갈 수 있도록, 최소 횟수의 발사 일정을 구한다.
난이도

어려움10점 중 8점

유형
그래프, 그리디, DFS
정답자
아직 제출이 없습니다

문제

A revolutionary new transport system is currently operating in Byteland. This system requires neither roads nor sophisticated mechanisms, only giant catapults.

The system works as follows. There are nn cities in Byteland. In every city there is a catapult, right in the city center. People who want to travel are put in a special capsule, and a catapult throws this capsule to the center of some other city. Every catapult is powerful enough to throw the capsule to any other city, with any number of passengers inside the capsule. The only problem is that it takes a long time to charge the catapult, so it is only possible to use it once a day.

The passenger may need to use the catapults multiple times. For example, if the passenger wants to travel from city A to city B, they can first use one catapult to move from A to C, and then transfer to another catapult to move from C to B.

Today there are mm passengers. Passenger ii wants to travel from city a_ia\_i to city b_ib\_i. Your task is to find the way to deliver all the passengers to their destinations in a single day, using the minimal possible number of catapults, or say that it is impossible.

입력

The first line of the input contains two integers nn and mm (1≤n≤10001 \leq n \leq 1000, 0≤m≤1050 \leq m \leq 10^5) --- the number of cities and the number of passengers. The next mm lines contain pairs of numbers a_ia\_i and b_ib\_i (1≤a_i,b_i≤n1 \leq a\_i, b\_i \leq n, a_i≠b_ia\_i \neq b\_i).

출력

In the first line print the number kk --- the minimal number of catapults you need to use.

In the next kk lines, print descriptions of each catapult launch, in the order they need to be performed. Each description should consist of two integers c_ic\_i, d_id\_i, the index of the city to launch from, and the index of destination city.

Note that you don't need to print what passengers should be put into the capsule on each launch, but it should be possible for each passenger to reach their destination city using the plan you provide.

If it is impossible to deliver all passengers, print the single number −1-1.

예제2

  1. 예제 1

    입력
    5 6
    1 3
    1 2
    2 3
    4 2
    1 5
    5 1
    
    예상 출력
    5
    5 1
    1 2
    4 2
    2 3
    3 5
    
  2. 예제 2

    입력
    3 6
    1 2
    1 3
    2 1
    2 3
    3 1
    3 2
    
    예상 출력
    -1