#FW0000087. Tổng khoảng cách sau từng pha Floyd (Shortest Path Queries 2)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng khoảng cách sau từng pha Floyd (Shortest Path Queries 2)
Shortest Path Queries 2
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given a directed positive-weighted graph, Floyd processes intermediate vertices in that order. After each phase sum finite shortest distances for every ordered pair and add this phase sum to a global answer. Print the sum over all phases.
Input
First , then directed positive-weight edges $u v w` using 1-based vertices. Parallel edges are allowed.
Output
Print a single 64-bit integer.
Subtasks
-
Subtask 1 (40 points): . , ; có thể có cạnh song song, cung có hướng.
-
Subtask 2 (60 points): . , ; có thể có cạnh song song, cung có hướng.
Examples
Input
3 3
1 2 1
2 3 2
1 3 10
Output
25
Explanation
Phase 1 contributes 13. Using vertex 2 as an intermediate reduces d(1,3) from 10 to 3, so phases 2 and 3 contribute 6 each; grand total 25.