ユニークビジョンプログラミングコンテスト2023 夏 (AtCoder Beginner Contest 312)
G
Avoid Straight Line
AtCoder
⌀ 1819
原题
← Ex→
翻译中…

Problem Statement

翻译中…

You are given a tree with $N$ vertices. The vertices are numbered from $1$ through $N$, and the $i$-th edge connects vertex $A_i$ and vertex $B_i$. Find the number of tuples of integers $(i,j,k)$ such that:

翻译中…
  • $1 \leq i < j < k \leq N$; and
  • the given tree does not contain a simple path that contains all of vertices $i$, $j$, and $k$.
翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq A_i, B_i \leq N$
  • The given graph is a tree.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 B_1
\vdots
A_{N-1} B_{N-1}

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
5
1 2
2 3
2 4
1 5
Output #1
2
Two tuples satisfy the conditions: $(i,j,k) = (1,3,4),(3,4,5)$.
Input #2
6
1 2
2 3
3 4
4 5
5 6
Output #2
0
Input #3
12
1 6
3 4
10 4
5 9
3 1
2 3
7 2
2 12
1 5
6 8
4 11
Output #3
91
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。