#P10842. 【MX-J2-T3】Piggy and Trees
【MX-J2-T3】Piggy and Trees
Background
Original problem link: https://oier.team/problems/J2D.
Problem Description
You are given a tree with nodes.
Define as the minimum value of among all nodes that satisfy $^\dagger\text{dis}(u, x) + \text{dis}(v, x) = \text{dis}(u, v)$.
Compute $\sum\limits_{u = 1}^n \sum\limits_{v = u + 1}^n \sum\limits_{i = 1}^n f(u, v, i)$ modulo .
is the length of the path between nodes and in the tree. In particular, .
Input Format
The first line contains an integer , representing the number of nodes in the tree.
Each of the following lines contains two integers , representing an edge in the tree.
Output Format
Output one line containing one integer, representing the answer.
4
1 2
1 3
1 4
9
6
1 2
2 3
3 4
4 5
5 6
70
10
1 2
1 3
1 4
2 5
3 6
2 7
4 8
8 9
9 10
536
Hint
Sample Explanation
In sample , all non-zero values of are:
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- .
Constraints
This problem uses bundled testdata and subtask dependencies are enabled.
| Subtask ID | Score | Special Property | Dependencies | |
|---|---|---|---|---|
| None | None | |||
| None | ||||
| None |
For all testdata, , and the input graph is a tree.
Translated by ChatGPT 5