- Translate each rule into one explicit state update.
- Maintain the invariant after every processed item.
- Return the accumulated state once all relevant input has been handled.
Code notes
- 56 lines of Python from the credited upstream file abc243_e.py.
- The implementation visibly relies on sequence storage, ordered lookup.
- No explicit loop blocks detected.
Complexity
Count the number and nesting of passes over the input, then include the maintained containers in the memory estimate.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12 3 4def warshall_floyd(dist):5 '''6 Args:7 Distance matrix between two points.8 Returns:9 Matrix of shortest distance.10 Landau notation: O(n ** 3).11 '''12 13 v_count = len(dist[0])14 15 for k in range(v_count):16 for i in range(v_count):17 for j in range(v_count):18 dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])19 20 return dist21 22 23def main():24 import sys25 26 input = sys.stdin.readline27 28 n, m = map(int, input().split())29 edges = list()30 inf = 10 ** 1831 graph = [[inf] * n for _ in range(n)]32 33 for _ in range(m):34 ai, bi, ci = map(int, input().split())35 ai -= 136 bi -= 137 38 edges.append([ai, bi, ci])39 graph[ai][bi] = ci40 graph[bi][ai] = ci41 42 dist = warshall_floyd(graph)43 ans = 044 45 for ai, bi, ci in edges:46 for i in range(n):47 if dist[ai][i] + dist[i][bi] <= ci:48 ans += 149 break50 51 print(ans)52 53 54if __name__ == "__main__":55 main()56