結果
問題 | No.2642 Don't cut line! |
ユーザー | hato336 |
提出日時 | 2024-02-19 22:11:28 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,181 bytes |
コンパイル時間 | 561 ms |
コンパイル使用メモリ | 82,412 KB |
実行使用メモリ | 120,676 KB |
最終ジャッジ日時 | 2024-09-29 02:07:55 |
合計ジャッジ時間 | 34,473 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 129 ms
89,156 KB |
testcase_01 | AC | 1,299 ms
117,928 KB |
testcase_02 | AC | 1,443 ms
119,012 KB |
testcase_03 | AC | 1,468 ms
120,244 KB |
testcase_04 | AC | 1,281 ms
120,676 KB |
testcase_05 | AC | 1,261 ms
119,152 KB |
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 | WA | - |
testcase_16 | AC | 490 ms
106,392 KB |
testcase_17 | AC | 1,250 ms
115,052 KB |
testcase_18 | AC | 1,193 ms
116,904 KB |
testcase_19 | AC | 1,081 ms
110,344 KB |
testcase_20 | AC | 1,062 ms
107,248 KB |
testcase_21 | AC | 409 ms
103,552 KB |
testcase_22 | AC | 413 ms
102,660 KB |
testcase_23 | AC | 1,613 ms
118,988 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 1,064 ms
110,968 KB |
testcase_28 | AC | 1,440 ms
116,464 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 1,289 ms
111,452 KB |
testcase_32 | WA | - |
testcase_33 | AC | 138 ms
89,092 KB |
testcase_34 | AC | 137 ms
89,268 KB |
testcase_35 | AC | 126 ms
85,560 KB |
ソースコード
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)