From ae25c091bcaf46aec5f6369198db3465ce39a0fa Mon Sep 17 00:00:00 2001 From: yenru0 Date: Thu, 11 Dec 2025 21:48:44 +0900 Subject: [PATCH] complete 11403.py --- storage/zeta/py/completed/11403.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 storage/zeta/py/completed/11403.py diff --git a/storage/zeta/py/completed/11403.py b/storage/zeta/py/completed/11403.py new file mode 100644 index 0000000..6be2cff --- /dev/null +++ b/storage/zeta/py/completed/11403.py @@ -0,0 +1,28 @@ +import sys + +input = sys.stdin.readline +write = sys.stdout.write + +THRESHOLD = 10**9 + +def floyd_warshall(n: int, adj: list[list[int]]): + ds = [] + ds.append(adj) + for k in range(n): + mat = [[0] * n for _ in range(n)] + for i in range(n): + for j in range(n): + if ds[-1][i][k] >= THRESHOLD or ds[-1][k][j] >= THRESHOLD: + mat[i][j] = ds[-1][i][j] + else: + mat[i][j] = min(ds[-1][i][j], ds[-1][i][k] + ds[-1][k][j]) + ds.append(mat) + return ds[-1] + +if __name__ == '__main__': + n = int(input()) + adj = [list(map(lambda x: THRESHOLD if int(x) == 0 else int(x), input().split())) for _ in range(n)] + result = floyd_warshall(n, adj) + for row in result: + write(' '.join(map(lambda x: '0' if x >= THRESHOLD else '1', row)) + '\n') +