Currents

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

요약
출구가 N-1인 방향 그래프에서 트롤이 최대 한 번 모든 간선을 뒤집고 출구를 0번 동굴로 바꿀 수 있을 때, 각 시작 동굴에서 반드시 탈출할 수 있는 최소 이동 횟수를 구한다. summaryEn을 만족합니다. 모든 조건을 충족합니다. 출력은 JSON입니다. 끝. summaryKo를 확인합니다. JSON 형식을 유지합니다. 주제는 graph, game-theory, dfs, dynamic-programming입니다. interview는 false, rating은 9입니다. 요약문은 160자 이내입니다. 한국어 요약은 합니다체입니다. JSON 스키마를 준수합니다. 추가 설명 없이 JSON만 출력합니다.
난이도

어려움10점 중 9점

유형
그래프, 게임 이론, DFS, 동적 계획법
정답자
아직 제출이 없습니다

문제

Well-hidden in the atrium of an abandoned house, you have found an ancient book that uncovers the most well-kept secret of the city of Bonn. Deep below the city, there is a system of NN caves, connected by MM water channels. Within each water channel there's a one-directional magical current that can quickly transport a boat along the channel. The cave system currently has exactly one exit that is located in cave N−1N-1.

You are very excited about your discovery and cannot wait to explore the caves! However, the cave system is inhabited by a troll who likes to have some fun with uninvited visitors. The troll has some limited magical power – which he can use at most once during your visit – to modify the cave system and make it harder for you to reach the exit.

Your visit to the cave system will consist of a sequence of rounds. Each round will be as follows:

  1. First, the troll gets to choose whether or not he uses his magical power. If he does, his spell does all of the following:

    • reverses the direction of the magical current in every channel: a→ba \rightarrow b will change to b→ab \rightarrow a immediately;
    • closes the exit in cave N−1N-1; and
    • opens a new exit in cave 00.
  2. Then, you choose a magical current that flows from your present cave, and use your boat to travel to another cave. For simplicity, we will call the use of a boat a "move".

Additionally, whenever you are in the same cave as the exit, you will immediately use it to leave the cave system. Note that this can even happen during a round if you are in cave 00 and the troll decides to use his magical power.

Your goal is to leave the cave system as quickly as possible to be in time for the closing ceremony of the EGOI. The troll's goal is exactly the opposite; he wants to keep you in his caves for as long as possible. The troll always knows your location and he will pick the moment at which to use his magical power in a way that serves his goal the best.

Separately for each cave cc (0≤c≤N−20 \leq c \leq N-2) consider the scenario in which you start in cave cc. For each of these scenarios, determine the smallest number of moves in which you can definitely reach an exit from cave cc, no matter when the troll chooses to use his power.

Assuming the spell is not used, every cave is reachable from cave 00, and cave N−1N-1 is reachable from every cave.

입력

The first line of the input contains two integers, NN and MM, where NN is the number of caves and MM is the number of water channels. The next MM lines of the input each contain two integers, a_ia\_i and b_ib\_i, representing a channel that right now can be used to travel from cave a_ia\_i to cave b_ib\_i. There is no channel connecting a cave to itself. For each pair of caves there is at most one channel in each direction.

출력

Output a line with N−1N-1 integers, where the iith integer, 0≤i≤N−20 \leq i \leq N-2, is the smallest number of moves within which you can definitely reach an exit if starting from cave ii.

Note that you do not output the time for cave N−1N - 1 (as you would just exit this cave immediately).

제한

  • 2≤N≤200,0002 \leq N \leq 200\\,000.
  • 1≤M≤500,0001 \leq M \leq 500\\,000.
  • 0≤a_i,b_i≤N−10 \leq a\_i, b\_i \leq N-1 and a_i≠b_ia\_i \neq b\_i.
  • Before the reversal, cave 00 can reach all caves, and cave N−1N-1 can be reached from all caves.

예제2

  1. 예제 1

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

    입력
    7 10
    2 6
    5 3
    4 2
    1 6
    2 3
    3 6
    4 5
    0 4
    4 1
    0 1
    
    예상 출력
    2 1 2 3 2 4