#P15805. [GESP202603 八级] 子图最短路
[GESP202603 八级] 子图最短路
Background
Related multiple-choice and true/false questions: https://ti.luogu.com.cn/problemset/1212.
Problem Description
Given a weighted undirected graph with nodes and edges, the nodes are numbered in order. The -th edge () connects two nodes numbered and , with weight .
For given , construct a subgraph of as follows:
- Keep the nodes in whose numbers are in the interval . Delete all other nodes whose numbers are not in and the edges incident to them. The remaining nodes and edges form the subgraph .
For any nodes in , we have . Let the shortest distance between and in the subgraph be . In particular, if and are not connected in , then define .
You need to compute $\sum_{\ell=1}^{n} \sum_{r=\ell}^{n} \sum_{u=\ell}^{r} \sum_{v=u}^{r} d(\ell, r, u, v)$ modulo .
- In this problem, the English letter is written as to avoid confusion between the letter and the digit .
Input Format
The first line contains two positive integers , representing the number of nodes and the number of edges.
The next lines: the -th line () contains three positive integers , representing an edge connecting nodes and with weight .
Output Format
Output one line with one integer, representing $\sum_{\ell=1}^{n} \sum_{r=\ell}^{n} \sum_{u=\ell}^{r} \sum_{v=u}^{r} d(\ell, r, u, v)$ modulo .
3 2
1 2 1
2 3 2
9
4 6
1 2 100
2 3 100
3 4 100
1 3 10
2 4 10
1 4 1
784
Hint
For of the testdata, it is guaranteed that .
For all testdata, it is guaranteed that , , , and . There may be multiple edges in the graph.
Translated by ChatGPT 5