#d1303. 三角果计数

三角果计数

Triangle-Fruit Counting

Problem Description

Given a tree with nn nodes, a "triangle-fruit" is defined as a set of 33 nodes whose pairwise shortest-path distances a,b,ca, b, c can form a triangle.

Count how many distinct triangle-fruits the tree has.

Note: two sets are the same if and only if A⊆BA \subseteq B and B⊆AB \subseteq A.

Input Format

The first line contains a positive integer nn, the number of nodes in the tree.

The next n−1n-1 lines each contain three integers u,v,wu, v, w, indicating an edge of weight ww between nodes uu and vv.

Output Format

Output one integer: the answer.

Sample Input

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

Sample Output

8

Constraints

For all data: 1≤n≤1051 \le n \le 10^5, edge weight 1≤w≤1051 \le w \le 10^5, 1≤u,v≤n1 \le u, v \le n.