結果
問題 | No.2387 Yokan Factory |
ユーザー |
|
提出日時 | 2024-01-07 13:30:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,707 ms / 5,000 ms |
コード長 | 1,406 bytes |
コンパイル時間 | 344 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 268,972 KB |
最終ジャッジ日時 | 2024-09-27 19:22:43 |
合計ジャッジ時間 | 33,079 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
## https://yukicoder.me/problems/no/2387import heapqdef solve(N, next_node, X, width):fix = {}seen = {0:0}queue= []heapq.heappush(queue, (0, 0))while len(queue) > 0:cost, v = heapq.heappop(queue)if v in fix:continuefix[v] = costfor next_v, a, b in next_node[v]:if next_v in fix:continueif b < width:continuenew_cost = cost + aif next_v not in seen or seen[next_v] > new_cost:seen[next_v] = new_costheapq.heappush(queue, (new_cost, next_v))if (N - 1) not in fix:return Falseelse:return fix[N - 1] <= Xdef main():N, M, X = map(int, input().split())next_node = [[] for _ in range(N)]max_b = 0for _ in range(M):u, v, a,b= map(int, input().split())next_node[u - 1].append((v - 1, a, b))next_node[v - 1].append((u - 1, a, b))max_b = max(max_b, b)low = 0high = max_bwhile high - low > 1:mid = (high + low) // 2if solve(N, next_node, X, mid):low = midelse:high = midif solve(N, next_node, X, high):v = highelse:v = lowif v == 0:print(-1)else:print(v)if __name__ == "__main__":main()