結果

問題 No.1320 Two Type Min Cost Cycle
コンテスト
ユーザー maspy
提出日時 2020-12-11 20:18:52
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 643 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 690 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 66,876 KB
最終ジャッジ日時 2026-04-08 13:52:44
合計ジャッジ時間 63,802 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52 TLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

T = int(readline())
N, M = map(int, readline().split())
frm, to, cost = np.array(read().split(), np.int64).reshape(-1, 3).T

G = csr_matrix((cost, (frm, to)), (N + 1, N + 1), dtype=np.float64)

ans = np.inf
for u, v, c in zip(frm, to, cost):
    G[u, v] = np.inf
    x = c + dijkstra(G, directed=T, indices=[v])[0, u]
    ans = min(ans, x)
    G[u, v] = c

if ans == np.inf:
    ans = -1
else:
    ans = int(ans + .5)
print(ans)
0