結果
問題 | No.2569 はじめてのおつかいHard |
ユーザー |
![]() |
提出日時 | 2023-12-02 16:22:53 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,300 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 82,300 KB |
実行使用メモリ | 156,000 KB |
最終ジャッジ日時 | 2024-09-26 20:13:05 |
合計ジャッジ時間 | 15,397 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 TLE * 1 |
ソースコード
#緑以下Ex-Aimport heapq as hqimport sys; input = sys.stdin.readline#入力受取N,M = map(int,input().split())#G[i][x]: xは0なら行き、1なら帰りG = [[[] for _ in range(2)] for _ in range(N)]for _ in range(M):u,v,t = map(lambda x:int(x)-1,input().split()); t+=1G[u][0].append((v,t)); G[v][1].append((u,t))#dist_1[k][x]: x=0なら町N-2→町k, x=1なら町k→町N-2#dist_1[2*k+x] に一次元化dist_1 = [10**18]*2*NQ = [(0,N-2,0),(0,N-2,1)]while Q:time,now,x = hq.heappop(Q)if dist_1[2*now+x] < time: continuedist_1[2*now+x] = timefor next,cost in G[now][x]:if dist_1[2*next+x] > time + cost:hq.heappush(Q,(time+cost, next, x))#dist_2[k]: 町N-1→町k, 町k→町N-1#dist_2[2*k+x]に一次元化dist_2 = [10**18]*2*NQ = [(0,N-1,0),(0,N-1,1)]while Q:time,now,x = hq.heappop(Q)if dist_2[2*now+x] < time: continuedist_2[2*now+x] = timefor next,cost in G[now][x]:if dist_2[2*next+x] > time + cost:hq.heappush(Q,(time+cost, next, x))#順に答えを出力for k in range(N-2):ans = 10**18ans = min(ans, dist_1[2*k+1] + dist_1[2*(N-1)+0] + dist_2[2*k+0])ans = min(ans, dist_2[2*k+1] + dist_2[2*(N-2)+0] + dist_1[2*k+0])print(ans if ans < 10**18 else -1)