luogu#P7980. [JRKSJ R3] a question
[JRKSJ R3] a question
Background
This is a question.
Problem Description
Now there is a tree with nodes. The edges are weighted, and the node labels form a permutation of .
Let be the complement graph of . For each edge in , its weight is the sum of edge weights along the path in .
Let be the length of the shortest path between nodes and in . If and are not connected, define .
Compute $\displaystyle\sum_{i=1}^{n-1} \sum_{j=i+1}^n dis(i,j)$.
Input Format
All numbers in the input are integers.
The first line contains one integer .
The next lines each contain three integers , indicating that there is an edge in connecting and with weight .
Output Format
Output one integer representing the answer. Since the answer can be very large, output it modulo .
3
1 2 2
2 3 3
5
4
1 2 4
2 3 4
3 4 4
96
Hint
The complement graph of is defined as follows: for an edge , if this edge does not exist in , then it exists in ; if this edge exists in , then it does not exist in . is an undirected graph.
Sample Explanation
For sample , the graph is shown in the figure:

We have: | | | | | | | :----------: | :----------: | :----------: | :----------: | :----------: | | | | | | | | | | | | | | | | | | |
So the answer is .
Constraints
| Special Property | Score | Dependencies | ||
|---|---|---|---|---|
| None | None | |||
| The tree is a star | None | |||
| The tree is a chain | ||||
| None |
For of the testdata, , , .
The input file for this problem is large. Please use an appropriate fast input method.
Translated by ChatGPT 5