QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 1024 MB Points totaux : 100

#16603. Move

Statistiques

Given an undirected graph with $n$ vertices and $m$ edges, where vertices are numbered $1 \sim n$.

Initially, there is a robot holding an item at vertex $1$. You can perform the following operations: 1. The robot places the item at an adjacent vertex; 2. The robot picks up the item from an adjacent vertex; 3. A robot not holding an item moves to an adjacent vertex that does not have an item placed on it.

Operations 1 and 2 take $1$ unit of time, while operation 3 takes $0$ time.

Find the minimum time for the robot to move to each vertex $2 \sim n$ while holding the item.

Input

The first line contains: * $T$

The following are $T$ test cases. For each test case: $n \ m$ $u_1 \ v_1$ $\dots$ $u_m \ v_m$

Output

For each test case: A single line containing $n-1$ integers, representing the minimum time to reach each vertex $2 \sim n$ while holding the item. If it is impossible to reach a vertex, output $-1$.

Examples

Input 1

4
4 4
1 2
2 3
3 4
4 1
5 5
1 2
2 3
3 4
4 5
5 1
5 6
1 2
3 2
1 3
3 5
5 4
3 4
9 12
1 2
2 3
3 1
4 5
5 6
6 4
7 8
8 9
9 7
3 6
6 9
9 3

Output 1

-1 2 -1
4 2 2 4
2 2 4 4
2 2 6 6 4 6 6 4

Subtasks

Subtask ID Score $\sum n \le$ $\sum m \le$ Special Property
1 16 1000 2000 None
2 18 1000 $10^5$ None
3 14 5000 $5 \times 10^5$ None
4 17 $5 \times 10^5$ $5 \times 10^5$ Edges $(1, 2), (2, 3), \dots, (n-1, n), (n, 1)$ exist
5 12 $5 \times 10^5$ $5 \times 10^5$ The degree of all vertices does not exceed $3$
6 23 $5 \times 10^5$ $5 \times 10^5$ None

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.