You are given a tree consisting of \(N\) vertices. Its root is not fixed yet. The \(potential\) of a non-leaf vertex is the count of its children (distance of \(1\) from the vertex) with a non-zero \(potential\). The \(potential\) of a leaf vertex \(i\) is \(i \% 2\).
Your task is to calculate the \(potential\) of every possible root. Find an array \(A\) such that \(A[i]\) represents the \(potential\) of vertex \(i\) if the tree was rooted at \(i\).
Input Format:
- The first line of input contains a single integer \(T\), denoting the number of test cases.
- The first line of each test case contains a single integer, \(N\), denoting the number of vertices.
- The following \(N-1\) lines contain two integers \(u,v\) denoting an edge between vertex \(u\) and vertex \(v\).
Output Format:
For each test case, print an array \(A\) such that \(A[i]\) represents the \(potential\) of vertex \(i\) if the tree was rooted at \(i\).
Constraints:
\(1 <= T <= 10\)
\(3 <= N <= 10^5\)
\(0 <= u, v < N\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial