#abc208d. D - Shortest Path Queries 2
D - Shortest Path Queries 2
Score : points
问题描述
在高桥王国中,有 座城市和 条道路。
城市编号从 到 ,道路编号从 到 。第 条道路是一条单向道路,从城市 指向城市 ,通过这条道路需要花费 分钟。
令我们定义函数 为以下查询的答案:
- 计算从城市 到城市 所需的最短时间。在此条件下,除了城市 和 外,只允许经过编号为 至 的城市。若无法到达城市 或者 ,答案应为 。
计算所有三元组 对应的 值,并打印它们的总和。更正式地,输出 $\displaystyle \sum_{s = 1}^N \sum_{t = 1}^N \sum_{k = 1}^N f(s, t, k)$.
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are cities and roads in the Kingdom of Takahashi.
The cities are numbered through , and the roads are numbered through . Road is a one-way road that leads from City to City , and it takes minutes to go through it.
Let us define as the answer to the following query.
- Compute the minimum time needed to get from City to City . Here, other than the Cities and , it is only allowed to pass through Cities through . If City is unreachable or , the answer should be .
Compute for all triples and print the sum of them. More formally, print $\displaystyle \sum_{s = 1}^N \sum_{t = 1}^N \sum_{k = 1}^N f(s, t, k)$.
Constraints
- or , if .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print $\displaystyle \sum_{s = 1}^N \sum_{t = 1}^N \sum_{k = 1}^N f(s, t, k)$.
Sample Input 1
3 2
1 2 3
2 3 2
Sample Output 1
25
The triples such that are as follows.
- For : .
- For : .
- For : .
Sample Input 2
3 0
Sample Output 2
0
We have for all .
Sample Input 3
5 20
1 2 6
1 3 10
1 4 4
1 5 1
2 1 5
2 3 9
2 4 8
2 5 6
3 1 5
3 2 1
3 4 7
3 5 9
4 1 4
4 2 6
4 3 4
4 5 8
5 1 2
5 2 5
5 3 6
5 4 5
Sample Output 3
517
update @ 2024/3/10 09:22:01