結果

問題 No.2642 Don't cut line!
ユーザー hato336hato336
提出日時 2024-02-19 22:11:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,181 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 119,748 KB
最終ジャッジ日時 2024-02-19 22:11:59
合計ジャッジ時間 27,744 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,068 ms
117,528 KB
testcase_01 AC 1,054 ms
118,724 KB
testcase_02 AC 1,042 ms
118,660 KB
testcase_03 AC 1,042 ms
119,748 KB
testcase_04 AC 1,069 ms
119,144 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 399 ms
105,864 KB
testcase_16 AC 936 ms
115,680 KB
testcase_17 AC 1,004 ms
116,308 KB
testcase_18 AC 805 ms
109,744 KB
testcase_19 AC 825 ms
107,180 KB
testcase_20 AC 333 ms
103,180 KB
testcase_21 AC 347 ms
102,524 KB
testcase_22 AC 1,135 ms
117,488 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 834 ms
109,264 KB
testcase_27 AC 1,075 ms
116,352 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 981 ms
110,896 KB
testcase_31 WA -
testcase_32 AC 105 ms
84,704 KB
testcase_33 AC 121 ms
88,288 KB
testcase_34 AC 107 ms
84,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        group_members = collections.defaultdict(list)
        for member in range(self.n):
            group_members[self.find(member)].append(member)
        return group_members

    def __str__(self):
        return ''.join(f'{r}: {m}' for r, m in self.all_group_members().items())
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
input = sys.stdin.readline
n,k,c = map(int,input().split())
e = []
for i in range(k):
    u,v,w,p = map(int,input().split())
    u-=1
    v-=1
    e.append((p,w,u,v))
uf = UnionFind(n)
e.sort(key=lambda x:x[1])
ans = 0
for p,w,u,v in e:
    if uf.same(u,v) == False:
        ans += w 
        uf.union(u,v)
if ans > c:
    exit(print(-1))

e.sort()
l,r = 0,k
ans =0
for i in range(20):
    m = (l+r)//2
    uf = UnionFind(n)
    temp = 0
    uf.union(e[m][2],e[m][3])
    temp += e[m][1]

    for j in range(m):
        p,w,u,v = e[j]
        if uf.same(u,v) == False:
            uf.union(u,v)
            temp += w
    if uf.group_count() == 1 and temp <= c:
        ans = max(ans,e[m][0])
    if temp <= c:
        l = m
    else:
        r = m
print(ans)
0