結果
問題 | No.2387 Yokan Factory |
ユーザー | cleantted |
提出日時 | 2023-06-14 04:14:40 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 4,091 ms / 5,000 ms |
コード長 | 3,628 bytes |
コンパイル時間 | 211 ms |
コンパイル使用メモリ | 13,184 KB |
実行使用メモリ | 65,632 KB |
最終ジャッジ日時 | 2024-09-17 21:32:47 |
合計ジャッジ時間 | 34,058 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
13,824 KB |
testcase_01 | AC | 58 ms
13,696 KB |
testcase_02 | AC | 54 ms
13,696 KB |
testcase_03 | AC | 53 ms
13,952 KB |
testcase_04 | AC | 54 ms
13,952 KB |
testcase_05 | AC | 55 ms
13,824 KB |
testcase_06 | AC | 55 ms
13,824 KB |
testcase_07 | AC | 59 ms
13,824 KB |
testcase_08 | AC | 58 ms
13,824 KB |
testcase_09 | AC | 53 ms
13,824 KB |
testcase_10 | AC | 52 ms
13,696 KB |
testcase_11 | AC | 55 ms
13,952 KB |
testcase_12 | AC | 56 ms
13,824 KB |
testcase_13 | AC | 56 ms
13,824 KB |
testcase_14 | AC | 60 ms
13,824 KB |
testcase_15 | AC | 2,689 ms
61,636 KB |
testcase_16 | AC | 1,065 ms
64,760 KB |
testcase_17 | AC | 4,004 ms
65,632 KB |
testcase_18 | AC | 3,202 ms
58,980 KB |
testcase_19 | AC | 2,420 ms
44,732 KB |
testcase_20 | AC | 1,109 ms
41,820 KB |
testcase_21 | AC | 3,221 ms
54,868 KB |
testcase_22 | AC | 1,070 ms
39,012 KB |
testcase_23 | AC | 3,403 ms
44,744 KB |
testcase_24 | AC | 953 ms
41,048 KB |
testcase_25 | AC | 1,316 ms
32,524 KB |
testcase_26 | AC | 4,091 ms
49,344 KB |
testcase_27 | AC | 1,401 ms
52,936 KB |
testcase_28 | AC | 59 ms
14,464 KB |
testcase_29 | AC | 64 ms
14,720 KB |
testcase_30 | AC | 64 ms
14,720 KB |
testcase_31 | AC | 62 ms
14,208 KB |
testcase_32 | AC | 62 ms
13,952 KB |
testcase_33 | AC | 60 ms
14,080 KB |
testcase_34 | AC | 68 ms
14,592 KB |
testcase_35 | AC | 68 ms
14,464 KB |
testcase_36 | AC | 56 ms
14,080 KB |
testcase_37 | AC | 55 ms
13,824 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()