結果

問題 No.2642 Don't cut line!
ユーザー t98slidert98slider
提出日時 2024-03-13 02:11:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 518 ms / 4,000 ms
コード長 1,229 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 91,484 KB
最終ジャッジ日時 2024-03-13 02:11:19
合計ジャッジ時間 16,935 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 518 ms
91,356 KB
testcase_02 AC 506 ms
91,484 KB
testcase_03 AC 495 ms
91,484 KB
testcase_04 AC 508 ms
91,484 KB
testcase_05 AC 474 ms
91,356 KB
testcase_06 AC 437 ms
88,984 KB
testcase_07 AC 414 ms
89,260 KB
testcase_08 AC 415 ms
88,988 KB
testcase_09 AC 476 ms
89,248 KB
testcase_10 AC 443 ms
89,260 KB
testcase_11 AC 438 ms
89,116 KB
testcase_12 AC 486 ms
89,656 KB
testcase_13 AC 464 ms
89,372 KB
testcase_14 AC 429 ms
89,124 KB
testcase_15 AC 461 ms
89,656 KB
testcase_16 AC 405 ms
91,228 KB
testcase_17 AC 461 ms
89,240 KB
testcase_18 AC 476 ms
90,572 KB
testcase_19 AC 344 ms
86,668 KB
testcase_20 AC 380 ms
86,300 KB
testcase_21 AC 370 ms
88,140 KB
testcase_22 AC 317 ms
87,032 KB
testcase_23 AC 494 ms
91,064 KB
testcase_24 AC 274 ms
84,012 KB
testcase_25 AC 314 ms
84,600 KB
testcase_26 AC 425 ms
88,392 KB
testcase_27 AC 324 ms
85,652 KB
testcase_28 AC 426 ms
89,860 KB
testcase_29 AC 383 ms
87,144 KB
testcase_30 AC 367 ms
85,452 KB
testcase_31 AC 373 ms
87,872 KB
testcase_32 AC 359 ms
86,188 KB
testcase_33 AC 35 ms
53,460 KB
testcase_34 AC 34 ms
53,460 KB
testcase_35 AC 35 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin

class UnionFind():
    def __init__(self, n):
        self.parent_or_size = [-1] * n
        self.weight = [1 << 30] * n
    def leader(self, x):
        while self.parent_or_size[x] >= 0: x = self.parent_or_size[x]
        return x
    def merge(self, x, y, w):
        rx, ry = self.leader(x), self.leader(y)
        if rx == ry: return False
        if self.parent_or_size[rx] > self.parent_or_size[ry]: rx, ry = ry, rx
        self.parent_or_size[rx] += self.parent_or_size[ry]
        self.parent_or_size[ry] = rx
        self.weight[ry] = w
        return True
    def dist(self, x, y):
        ans = 0
        while x != y:
            if self.weight[x] > self.weight[y]: x, y = y, x
            ans = self.weight[x]
            x = self.parent_or_size[x]
        return ans

N, K, C = map(int, stdin.readline().split())
c, ans = 0, 0
uf = UnionFind(N)
E = [[] for _ in range(K)]
for i in range(K):
    u, v, w, p = map(int, stdin.readline().split())
    E[i] = [w, u - 1, v - 1, p]
E.sort()
for w, u, v, p in E:
    if uf.merge(u, v, w):
        c += w
        N -= 1
if N != 1 or c > C:
    print(-1)
    exit(0)
for w, u, v, p in E:
    if c - uf.dist(u, v) + w <= C: ans = max(ans, p)
print(ans)
0