Edges in Spanning Trees
All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.You are given two spanning trees $T_1$ and $T_2$ on the same set of $N$ vertices (numbered $1$ through $N$). For each edge $e_1$ in $T_1$, you have to calculate the number of edges $e_2 \in T_2$ which satisfy the following conditions: - $T_1 - e_1 + e_2$ (the graph formed by removing the edge $e_1$ from $T_1$ and adding the edge $e_2$) is a spanning tree - $T_2 - e_2 + e_1$ is also a spanning tree ### Input - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - Each of the following $N-1$ lines contains two space-separated integers $u$ and $v$ denoting an edge in $T_1$ between vertices $u$ and $v$. - The following $N-1$ lines describe the edges of $T_2$ in the same format. ### Output For each test case, print $N-1$ space-separated integers — the number of valid edges $e_2$ for each edge $e_1 \in T_1$ (in the order in which they are given on the input). ### Constraints - $1 \le T \le 10$ - $2 \le N \le 2 \cdot 10^5$ - the sum of $N$ over all test cases does not exceed $2 \cdot 10^5$ ### Subtasks **Subtask #1 (20 points):** the sum of $N$ over all test cases does not exceed $10^4$ **Subtask #2 (80 points):** original constraints ### Example Input ``` 1 4 1 2 1 3 1 4 1 2 2 3 3 4 ``` ### Example Output ``` 1 1 1 ```
|Tags||altruist_, heavy-light-decomposition, may18, segment-tree|
|Time Limit:||2 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions