QOJ.ac

QOJ

Time Limit: 0.7 s Memory Limit: 64 MB Total points: 100

#11292. Hotels

Statistics

There are n towns in Byteotia, connected with only $n-1$ roads. Each road directly links two towns. All the roads have the same length and are two way. It is known that every town can be reached from every other town via a route consisting of one or more (direct-link) roads. In other words, the road network forms a tree.

Byteasar, the king of Byteotia, wants three luxury hotels erected to attract tourists from all over the world. The king desires that the hotels be in different towns and at the same distance one from each other.

Help the king out by writing a program that determines the number of possible locations of the hotel triplet in Byteotia.

Input Format

The first line of the standard input contains a single integer $n$ ($1 \le n \le 5\,000$), the number of towns in Byteotia. The towns are numbered from $1$ to $n$.

The Byteotian road network is then described in $n-1$ lines. Each line contains two integers $a$ and $b$ ($1 ≤ a ≤ b ≤ n$) , separated by a single space, that indicate there is a direct road between the towns $a$ and $b$.

Output Format

The first and only line of the standard output should contain a single integer equal to the number of possible placements of the hotels.

Example

Input

7
1 2
5 7
2 5
2 3
5 6
4 5

Output

5
problem_11292_1.png

The triplets (unordered) of towns where the hotels can be erected are: {1,3,5}, {2,4,6}, {2,4,7}, {2,6,7}, {4,6,7}.

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.