시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
8 초 | 256 MB | 17 | 7 | 7 | 50.000% |
Given are trees $T_1$ and $T_2$. Each tree has $n$ vertices numbered from $1$ through $n$. Let $d(v, u, T)$ denote the number of edges on the path between vertices $v$ and $u$ in tree $T$. Calculate the following sum:
$$ \sum_{1 \le u < v \le n} \left(d(v, u, T_1) + d(v, u, T_2)\right)^2 \text{.} $$
As the answer may be large, find it modulo $2^{32}$.
The first line contains one integer $n$: the number of vertices in each tree ($1 \le n \le 100\,000$).
Each of the next $n - 1$ lines contains two integers, $u$ and $v$, denoting an edge between vertices $u$ and $v$ in tree $T_1$ ($1 \le u, v \le n$).
Each of the last $n - 1$ lines contains two integers, $u$ and $v$, denoting an edge between vertices $u$ and $v$ in tree $T_2$ ($1 \le u, v \le n$).
Print the answer modulo $2^{32}$.
3 1 2 1 3 1 2 1 3
24
3 1 2 1 3 1 2 2 3
22