結果

問題 No.807 umg tours
ユーザー maspy
提出日時 2020-02-27 16:08:05
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,450 ms / 4,000 ms
コード長 729 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 129,276 KB
最終ジャッジ日時 2024-10-13 15:58:07
合計ジャッジ時間 33,604 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
import numpy as np


# %%
N, M = map(int, readline().split())
ABC = np.array(read().split(), np.int64)
A = ABC[::3]
B = ABC[1::3]
C = ABC[2::3]


# %%
fr = np.concatenate([A, A, A + N, B, B, B + N])
to = np.concatenate([B, B + N, B + N, A, A + N, A + N])
cost = np.concatenate([C, np.zeros(M, np.int64), C] * 2)
G = csr_matrix((cost, (fr, to)), (N + N + 1, N + N + 1))

# %%
dist = dijkstra(G, directed=True, indices=1).astype(int)
x = dist[1: 1 + N] + dist[1 + N:]
x[0] = 0
print('\n'.join(x.astype(str)))
0