Make Them Meet

시간 제한9초메모리 제한1024 MB

요약
그래프 위의 두 사람이 어디에서 시작하든, 어떤 이동 선택을 하든 반드시 만나도록 등불 색을 2만 번 이하로 정하는 문제.
난이도

어려움10점 중 9점

유형
그래프, BFS, 그리디, 시뮬레이션
정답자
아직 제출이 없습니다

문제

Mila and Laura have been friends online for a long time; they have never met in real life. Currently, they are both attending the same onsite event, which means that they will surely meet. However, the hotel where they both are staying is very big and confusing. Therefore, after several days, they still have not run into each other.

The hotel consists of NN rooms, numbered 00 to N−1N-1. Each room has a lamp that can be changed into different colours. You have found the electrical service room of the hotel, allowing you to alter the colours of the lamps. Your goal is to guide Mila and Laura using the lamps to finally make them meet.

The hotel can be represented as a graph with NN vertices (the rooms) and MM edges (the corridors connecting the rooms). Mila and Laura initially start in two different rooms but you do not know which ones. You can make a number of moves. Each move consists of printing a list of NN integers, c_0,c_1,…,c_N−1c\_0, c\_1, \ldots, c\_{N-1}, meaning that the colour of the lamp in room ii becomes c_ic\_i for every i=0,1,…,N−1i = 0,1,\ldots,N-1. Mila and Laura will then look at the colour of the lamp in the room they are currently in and walk to a neighbouring room whose lamp has the same colour. If there is no such neighbouring room, they will stay where they are. If there are several such neighbouring rooms, they will choose one arbitrarily.

If Mila and Laura are in the same room or use the same corridor simultaneously at any point during your moves, you have succeeded in making them meet. You can make at most 20,00020\\,000 moves, but you will get a higher score if you use fewer moves.

Note that you do not know which rooms Mila and Laura start in or how they walk if they have multiple rooms with the same colour to choose from. Your solution must be correct regardless of their starting rooms or how they walk.

입력

The first line contains two integers, NN and MM, the number of rooms and the number of corridors in the hotel respectively.

The following MM lines each contain two integers, u_iu\_i and v_iv\_i, meaning that rooms u_iu\_i and v_iv\_i are connected by a corridor.

출력

Print one line with an integer KK, the number of moves.

On each of the following KK lines, print NN integers, c_0,c_1,…,c_N−1c\_0, c\_1, \ldots, c\_{N-1}, such that 0≤c_i≤N0\le c\_i\le N for all ii. These KK lines represent your moves in the chronological order.

제한

  • 2≤N≤1002 \leq N \leq 100.
  • N−1≤M≤N(N−1)2N-1 \leq M \leq \frac{N(N-1)}{2}.
  • 0≤u_i,v_i≤N−10 \leq u\_i, v\_i \leq N-1, and u_i≠v_iu\_{i}\neq v\_{i}.
  • You can reach every room from every other room. Furthermore, there are no corridors going from a room to itself, and there are not multiple corridors between any pair of rooms.
  • You may use at most 20,00020\\,000 moves (that is, K≤20,000K\le 20\\,000).

힌트

The sample case is a path of length 33, so it could belong to test groups 33, 44, or 55. If the lamps of the rooms are coloured according to the sample output, then Mila and Laura will always meet.

For example, let us assume that Mila starts in room 00 and Laura starts in room 11:

  • First move: Mila must walk to room 11. If Laura walks to room 00, then they will meet in the corridor between 00 and 11. Let us say that Laura walks to room 22 instead.
  • Second move: Mila walks back to room 00 and Laura stays in room 22.
  • Third move: Mila walks to room 11 again and Laura stays in room 22.
  • Fourth move: Mila walks to room 22 and Laura walks to room 11. Thus, they will meet on the corridor between rooms 11 and 22.
  • Fifth move: Mila and Laura swaps places and meet again (but it does not matter since they already met).

The figure below shows the first four moves of the sample.

Note that this was only the case where the friends start in the rooms 00 and 11. One can verify that the same sequence of moves ensures that they will meet, regardless of where they start and how they walk.

예제1

  1. 예제 1

    입력
    3 2
    0 1
    1 2
    
    예상 출력
    5
    2 2 2
    2 2 3
    2 2 3
    1 2 2
    1 2 2