結果

問題 No.2387 Yokan Factory
ユーザー cleanttedcleantted
提出日時 2023-06-14 03:44:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,311 ms / 5,000 ms
コード長 3,153 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 82,612 KB
実行使用メモリ 200,788 KB
最終ジャッジ日時 2024-06-23 20:12:17
合計ジャッジ時間 23,147 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 162 ms
90,704 KB
testcase_01 AC 168 ms
90,644 KB
testcase_02 AC 161 ms
90,668 KB
testcase_03 AC 166 ms
90,816 KB
testcase_04 AC 164 ms
90,920 KB
testcase_05 AC 167 ms
90,656 KB
testcase_06 AC 167 ms
90,880 KB
testcase_07 AC 212 ms
90,736 KB
testcase_08 AC 167 ms
90,992 KB
testcase_09 AC 161 ms
90,676 KB
testcase_10 AC 165 ms
90,496 KB
testcase_11 AC 167 ms
90,880 KB
testcase_12 AC 164 ms
90,652 KB
testcase_13 AC 163 ms
90,624 KB
testcase_14 AC 164 ms
90,880 KB
testcase_15 AC 1,054 ms
145,148 KB
testcase_16 AC 515 ms
134,932 KB
testcase_17 AC 1,329 ms
200,788 KB
testcase_18 AC 1,885 ms
151,312 KB
testcase_19 AC 1,270 ms
135,516 KB
testcase_20 AC 763 ms
118,452 KB
testcase_21 AC 1,827 ms
156,716 KB
testcase_22 AC 800 ms
119,048 KB
testcase_23 AC 1,915 ms
140,860 KB
testcase_24 AC 677 ms
115,772 KB
testcase_25 AC 912 ms
119,112 KB
testcase_26 AC 2,311 ms
149,468 KB
testcase_27 AC 900 ms
137,960 KB
testcase_28 AC 205 ms
94,208 KB
testcase_29 AC 221 ms
93,584 KB
testcase_30 AC 213 ms
93,824 KB
testcase_31 AC 221 ms
93,788 KB
testcase_32 AC 204 ms
93,260 KB
testcase_33 AC 208 ms
93,568 KB
testcase_34 AC 227 ms
93,976 KB
testcase_35 AC 234 ms
94,332 KB
testcase_36 AC 195 ms
93,428 KB
testcase_37 AC 167 ms
90,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 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 main():
    N, M, X = read_values() 
    G = [[] for _ in range(N)]

    for _ in range(M):
        u, v, a, b = read_values()
        u -= 1
        v -= 1

        G[u].append((v, a, b))
        G[v].append((u, a, b))
    
    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 j, a, b in G[i]:
                if m > b:
                    continue

                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()
0