The Tree Problem
Limits: 2 sec., 256 MiB
You are given a tree — a non-directed connected acyclic graph, containing \(n\) nodes and \(n-1\) edges. We will consider the tree nodes numbered by integers from 1 to \(n\).
You wonder, how to find the number of pairs of paths that don’t have common nodes. More formally, you should find the number of groups of four integers \(a, b, c\) and \(d\) such that:
\(1 \le a < b \le n\);
\(1 \le c < d \le n\);
there’s no such node that lies on both the shortest path from node \(a\) to node \(b\) and from node \(c\) to node \(d\).
The shortest path betweem two nodes is the path that is shortest in the number of edges.
Find the number of such pathes.
Input
The first line contains integer \(n\) — the number of tree nodes. Each of the following \(n-1\) lines contains a pair of integers \(u_i\) and \(v_i\) — the \(i\)-th edge of the tree.
It is guaranteed that the given graph is a tree.
Output
In a single line print a single integer — the answer to the problem.
Constraints
\(1 \le n \le 80000\),
\(1 \le u_i, v_i \le n; ~ u_i \ne v_i\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 4 1 2 2 3 3 4 | 2 |
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|