結果
問題 | No.2387 Yokan Factory |
ユーザー | cleantted |
提出日時 | 2023-06-14 04:12:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,343 ms / 5,000 ms |
コード長 | 3,628 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 82,416 KB |
実行使用メモリ | 214,600 KB |
最終ジャッジ日時 | 2024-06-23 20:12:50 |
合計ジャッジ時間 | 25,000 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 175 ms
91,152 KB |
testcase_01 | AC | 166 ms
91,088 KB |
testcase_02 | AC | 166 ms
91,040 KB |
testcase_03 | AC | 171 ms
90,896 KB |
testcase_04 | AC | 172 ms
90,740 KB |
testcase_05 | AC | 169 ms
90,860 KB |
testcase_06 | AC | 169 ms
91,112 KB |
testcase_07 | AC | 167 ms
90,804 KB |
testcase_08 | AC | 169 ms
91,064 KB |
testcase_09 | AC | 170 ms
90,904 KB |
testcase_10 | AC | 168 ms
90,940 KB |
testcase_11 | AC | 168 ms
91,108 KB |
testcase_12 | AC | 169 ms
91,260 KB |
testcase_13 | AC | 171 ms
90,948 KB |
testcase_14 | AC | 167 ms
91,008 KB |
testcase_15 | AC | 1,208 ms
156,516 KB |
testcase_16 | AC | 675 ms
143,780 KB |
testcase_17 | AC | 1,791 ms
214,600 KB |
testcase_18 | AC | 2,107 ms
159,248 KB |
testcase_19 | AC | 1,439 ms
139,388 KB |
testcase_20 | AC | 918 ms
127,084 KB |
testcase_21 | AC | 2,125 ms
166,168 KB |
testcase_22 | AC | 904 ms
123,264 KB |
testcase_23 | AC | 2,104 ms
146,920 KB |
testcase_24 | AC | 782 ms
122,504 KB |
testcase_25 | AC | 1,034 ms
125,660 KB |
testcase_26 | AC | 2,343 ms
158,820 KB |
testcase_27 | AC | 1,014 ms
151,188 KB |
testcase_28 | AC | 206 ms
93,680 KB |
testcase_29 | AC | 234 ms
94,624 KB |
testcase_30 | AC | 236 ms
94,568 KB |
testcase_31 | AC | 233 ms
94,136 KB |
testcase_32 | AC | 202 ms
93,132 KB |
testcase_33 | AC | 205 ms
93,140 KB |
testcase_34 | AC | 253 ms
94,824 KB |
testcase_35 | AC | 232 ms
94,408 KB |
testcase_36 | AC | 183 ms
91,508 KB |
testcase_37 | AC | 167 ms
91,000 KB |
ソースコード
# import bisect import copy import heapq import itertools import math import operator import random import sys from bisect import bisect, bisect_left, bisect_right, insort from collections import Counter, deque from fractions import Fraction from functools import cmp_to_key, lru_cache, partial from inspect import currentframe from math import ceil, gcd, log10, pi, sqrt from typing import Iterable, Iterator, List, Tuple, TypeVar, Union # import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') # import string # import networkx as nx input = sys.stdin.readline sys.setrecursionlimit(10000000) # mod = 10 ** 9 + 7 mod = 998244353 # mod = 1 << 128 # mod = 10 ** 30 + 1 INF = 1 << 61 DIFF = 10 ** -9 DX = [1, 0, -1, 0, 1, 1, -1, -1] DY = [0, 1, 0, -1, 1, -1, 1, -1] def read_values(): return tuple(map(int, input().split())) def read_index(): return tuple(map(lambda x: int(x) - 1, input().split())) def read_list(): return list(read_values()) def read_lists(N): return [read_list() for _ in range(N)] def dprint(*values): print(*values, file=sys.stderr) def dprint2(*values): names = {id(v): k for k, v in currentframe().f_back.f_locals.items()} dprint(", ".join(f"{names.get(id(value), '???')}={repr(value)}" for value in values)) class UnionFind: def __init__(self, N): self.state = [-1] * N self.rank = [0] * N self.num_group = N def get_parent(self, a): p = self.state[a] if p < 0: return a q = self.get_parent(p) self.state[a] = q return q def make_pair(self, a, b): pa = self.get_parent(a) pb = self.get_parent(b) if pa == pb: return if self.rank[pa] > self.rank[pb]: pa, pb = pb, pa a, b = b, a elif self.rank[pa] == self.rank[pb]: self.rank[pb] += 1 self.state[pb] += self.state[pa] self.state[pa] = pb self.state[a] = pb self.num_group -= 1 def is_pair(self, a, b): return self.get_parent(a) == self.get_parent(b) def get_size(self, a): return -self.state[self.get_parent(a)] def validate(N, M, X, L): assert(1 <= N <= 2 * 10 ** 5) assert(1 <= M <= 2 * 10 ** 5) assert(1 <= X <= 10 ** 18) assert(len(L) == M) uf = UnionFind(N) for u, v, a, b in L: assert(1 <= u <= N) assert(1 <= v <= N) assert(1 <= a <= 10 ** 9) assert(1 <= b <= 10 ** 9) u -= 1 v -= 1 uf.make_pair(u, v) assert uf.get_size(0) == N assert uf.num_group == 1 def main(): N, M, X = read_values() L = read_lists(M) G = [[] for _ in range(N)] for u, v, a, b in L: u -= 1 v -= 1 G[u].append((b, v, a)) G[v].append((b, u, a)) for i in range(N): G[i].sort(reverse=True) def f(m): S = [(0, 0)] fixed = [False] * N D = [INF] * N D[0] = 0 while S: c, i = heapq.heappop(S) if i == N - 1: break if fixed[i]: continue fixed[i] = True for b, j, a in G[i]: if m > b: break if D[j] <= c + a: continue D[j] = c + a heapq.heappush(S, (c + a, j)) return D[N - 1] <= X l = -1 r = 10 ** 9 + 10 while r - l > 1: m = (l + r) // 2 if f(m): l = m else: r = m print(l) if __name__ == "__main__": main()