13071307 SUSTech Online Judge
Problem 1307 --Problem 4

1307: Problem 4

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 47  Solved: 19
[Submit][Status][Web Board]

Description

给一棵\(n\)个节点的树,根节点为\(1\),求每个节点的深度(根节点深度为\(0\))。

Input

第一行为一个整数\(T(1\leq T\leq 10)\),表示测试数据的个数。

对于每组测试数据,第一行为一个整数\(n(1\leq n\leq 10^5)\),表示节点的个数。接下来的\(n-1\)行,每行有两个整数\(u\)和\(v(1\leq u,v\leq n)\),表示\(u\)、\(v\)之间有一条边。

Output

依次输出每个节点的深度。

Sample Input

1
4
1 2
1 3
4 2

Sample Output

0 1 1 2

HINT

Source

 

[Submit][Status]