Whimsical Happening

0

0 votes
Medium
Problem

“I’m not a psychopath, Anderson. I’m a high-functioning sociopath. Do your research.” -Sherlock

Problem 4:

Given the start and the finish time of visiting all the vertex in the tree. You need to output the cardinality of all the vertex.

time=0
void dfs(int s)
{
    start[s]=++time
    visit[s]=true
    for each x adjacent to s:
        if visit[x] :
            continue
        dfs(x)
    end[s]=time 
}
Note : cardinality of a vertex is the total number of edges which are connected to it.

Input:

First line of the input contains T representing the number of test cases in the input.

First line of each test case contains a single integer n representing the total number of vertex in the tree.

Second line contains n space separated integers denoting the start time of the \(jth\) vertex;

Third line contains n space separated integers denoting the finish time of the \(jth\) vertex.

Output:

Output is of single line representing space separated integers on a single line corresponding to every vertex. For more clarity see the sample.

Constraints :

\(1 \le T \le 10 \)

\(1 \le n \le 10^5 \)

\( 1 \le s[j] \le f[j] \le n \)

here \(s[j]\) and \(f[j]\) are the start and finish time of the \(jth\) vertex.

Sample Input
4
4
2 4 1 3
2 4 4 4
4
2 4 3 1
4 4 4 4
4
4 1 2 3
4 4 3 3
5
5 1 3 2 4
5 5 5 5 5
Sample Output
1 1 2 2 
2 1 2 1 
1 2 2 1 
1 1 2 2 2
Time Limit: 1
Memory Limit: 256
Source Limit:
Contributers:
Editor Image

?