結果
問題 | No.2387 Yokan Factory |
ユーザー |
![]() |
提出日時 | 2025-03-20 20:18:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,788 ms / 5,000 ms |
コード長 | 1,579 bytes |
コンパイル時間 | 136 ms |
コンパイル使用メモリ | 82,108 KB |
実行使用メモリ | 200,512 KB |
最終ジャッジ日時 | 2025-03-20 20:19:47 |
合計ジャッジ時間 | 15,723 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
import heapqdef main():import sysinput = sys.stdin.read().split()ptr = 0N = int(input[ptr])ptr += 1M = int(input[ptr])ptr += 1X = int(input[ptr])ptr += 1edges = [[] for _ in range(N)]max_b = 0for _ in range(M):u = int(input[ptr]) - 1ptr += 1v = int(input[ptr]) - 1ptr += 1a = int(input[ptr])ptr += 1b = int(input[ptr])ptr += 1edges[u].append((v, a, b))edges[v].append((u, a, b))if b > max_b:max_b = blow = 0high = max_b + 1ans = -1inf = 1 << 60while low < high:mid = (low + high) // 2dist = [inf] * Ndist[0] = 0heap = [(0, 0)]found = Falsepossible = Falsewhile heap:d, u = heapq.heappop(heap)if u == N - 1:found = Truepossible = (d <= X)breakif d > dist[u]:continuefor (v, a, b) in edges[u]:if b >= mid:new_d = d + aif new_d < dist[v]:dist[v] = new_dheapq.heappush(heap, (new_d, v))if not found:possible = Falseelse:possible = possible or (dist[N-1] <= X)if possible:ans = midlow = mid + 1else:high = midprint(ans if ans != -1 else -1)if __name__ == '__main__':main()