結果
| 問題 | 
                            No.1320 Two Type Min Cost Cycle
                             | 
                    
| コンテスト | |
| ユーザー | 
                             maspy
                         | 
                    
| 提出日時 | 2020-12-11 20:18:52 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                            (最新)
                                AC
                                 
                             
                            (最初)
                            
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 643 bytes | 
| コンパイル時間 | 115 ms | 
| コンパイル使用メモリ | 12,416 KB | 
| 実行使用メモリ | 151,060 KB | 
| 最終ジャッジ日時 | 2024-09-20 01:24:05 | 
| 合計ジャッジ時間 | 79,517 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 51 TLE * 6 | 
ソースコード
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)
            
            
            
        
            
maspy