結果
問題 | No.3013 ハチマキ買い星人 |
ユーザー |
![]() |
提出日時 | 2025-01-27 12:13:36 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 733 ms / 2,000 ms |
コード長 | 1,284 bytes |
コンパイル時間 | 400 ms |
コンパイル使用メモリ | 82,348 KB |
実行使用メモリ | 115,984 KB |
最終ジャッジ日時 | 2025-01-27 12:13:58 |
合計ジャッジ時間 | 21,621 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 45 |
ソースコード
import sysinput = sys.stdin.readlinefrom heapq import heappush, heappopinf = float('inf')def dijkstra(s, g, N):# ゴールがない場合はg=-1とする。def cost(v, m):return v * N + mdist = [inf] * Nmindist = [inf] * Nseen = [False] * NQ = [cost(0, s)]while Q:c, m = divmod(heappop(Q), N)if seen[m]:continueseen[m] = Truedist[m] = cif m == g:return dist#------heapをアップデートする。--------for u, C in G[m]:if seen[u]:continuenewdist = dist[m] + C#------------------------------------if newdist >= mindist[u]:continuemindist[u] = newdistheappush(Q, cost(newdist, u))return distN, M, P, Y = map(int, input().split())G = [[] for i in range(N)]for i in range(M):a, b, c = map(int, input().split())a, b = a - 1, b - 1G[a].append((b, c))G[b].append((a, c))inf = 10 ** 18 + 5hachi = [inf] * Nfor i in range(P):d, e = map(int, input().split())hachi[d - 1] = eD = dijkstra(0, -1, N)ans = 0for i in range(N):ans = max(ans, (Y - D[i])//hachi[i])print(ans)