#P16644. [GKS 2018 #C] Planet Distance

[GKS 2018 #C] Planet Distance

Problem Description

There are NN planets in the universe, and Google's Space division has installed NN vacuum tubes through which you can travel from one planet to another. The tubes are bidirectional; travelers may use a tube between two planets to travel from either of those planets to the other. Each vacuum tube connects two planets and no two vacuum tubes connect the same pair of planets. These tubes connect the planets such that it is possible to travel from any planet to any other planet using one or more of them. Some of these tubes are connected such that there exists exactly one cycle in the universe. Google has hidden gifts in all the planets that are part of this cycle. Now, Google wants to know how far away each of the planets in the universe is from the gifts.

Your task is to find the minimum distance (in terms of the number of vacuum tubes) between each planet and a planet that is part of the cycle. Planets that are part of the cycle are assumed to be at distance 0.

Input Format

The first line contains an integer TT, the number of test cases. TT test cases follow. The first line of each test case contains an integer NN, the number of planets and vacuum tubes. The planets are numbered from 1 to NN.

NN lines follow, the i-th of these lines contains two integers xix_i and yiy_i, indicating that the i-th vacuum tube connects planet xix_i and planet yiy_i.

Output Format

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is a list of N space-separated values in which the i-th value represents the minimum distance between the i-th planet and a planet in the cycle.

2
5
1 2
2 3
3 4
2 4
5 3
3
1 2
3 2
1 3
Case #1: 1 0 0 0 1
Case #2: 0 0 0

Hint

In Sample Case #1, the cycle consists of planets 22, 33, and 44. Therefore, the distances for planets 22, 33, and 44 are 00. There is a vacuum tube between 11 and 22, and another vacuum tube between 33 and 55. Thus, planets 11 and 55 are at a distance 11 from the cycle.

In Sample Case #2, all the planets are part of the cycle. Hence, their distances are 00.

Limits

1T1001 \le T \le 100.

1xiN1 \le x_i \le N, for all ii.

1yiN1 \le y_i \le N, for all ii.

xiyix_i \neq y_i, for all ii.

(xi,yi)(xj,yj)(x_i, y_i) \neq (x_j, y_j), for all iji \neq j.

The graph in which planets are nodes and tubes are edges is connected and has exactly one cycle.

Small dataset (Test set 1 - Visible)

3N303 \le N \le 30.

Large dataset (Test set 2 - Hidden)

3N10003 \le N \le 1000.