結果
問題 | No.2642 Don't cut line! |
ユーザー | こめだわら |
提出日時 | 2024-02-19 22:46:13 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,158 bytes |
コンパイル時間 | 239 ms |
コンパイル使用メモリ | 82,032 KB |
実行使用メモリ | 120,464 KB |
最終ジャッジ日時 | 2024-09-29 02:38:40 |
合計ジャッジ時間 | 49,485 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,196 KB |
testcase_01 | AC | 1,446 ms
120,080 KB |
testcase_02 | AC | 1,508 ms
120,324 KB |
testcase_03 | AC | 1,481 ms
120,456 KB |
testcase_04 | AC | 1,460 ms
119,812 KB |
testcase_05 | AC | 1,501 ms
120,464 KB |
testcase_06 | AC | 1,773 ms
104,748 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 1,710 ms
104,360 KB |
testcase_10 | AC | 1,940 ms
103,972 KB |
testcase_11 | AC | 1,911 ms
104,996 KB |
testcase_12 | AC | 2,038 ms
106,640 KB |
testcase_13 | AC | 1,956 ms
105,628 KB |
testcase_14 | AC | 1,967 ms
104,232 KB |
testcase_15 | AC | 1,972 ms
106,024 KB |
testcase_16 | AC | 544 ms
106,028 KB |
testcase_17 | AC | 1,342 ms
113,848 KB |
testcase_18 | AC | 1,459 ms
116,272 KB |
testcase_19 | AC | 1,058 ms
106,156 KB |
testcase_20 | AC | 1,357 ms
99,688 KB |
testcase_21 | AC | 465 ms
99,348 KB |
testcase_22 | AC | 426 ms
99,600 KB |
testcase_23 | AC | 1,998 ms
119,520 KB |
testcase_24 | AC | 1,033 ms
97,056 KB |
testcase_25 | AC | 1,120 ms
98,952 KB |
testcase_26 | AC | 1,684 ms
101,656 KB |
testcase_27 | AC | 1,188 ms
103,612 KB |
testcase_28 | AC | 1,748 ms
113,832 KB |
testcase_29 | AC | 1,580 ms
100,220 KB |
testcase_30 | AC | 1,283 ms
98,368 KB |
testcase_31 | AC | 1,518 ms
107,704 KB |
testcase_32 | AC | 1,368 ms
100,296 KB |
testcase_33 | AC | 37 ms
53,044 KB |
testcase_34 | AC | 38 ms
53,392 KB |
testcase_35 | AC | 38 ms
53,896 KB |
ソースコード
class UnionFind: def __init__(self, n): self._n = n self.parent_or_size = [-1] * n def merge(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n x, y = self.leader(a), self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a): assert 0 <= a < self._n alist=[] while self.parent_or_size[a] >= 0: alist.append(a) a = self.parent_or_size[a] for i in alist: self.parent_or_size[i] = a return a def size(self, a): assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf = [self.leader(i) for i in range(self._n)] result = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return [r for r in result if r != []] N,K,C=map(int,input().split()) edge=[] edge_s=[] edge_w=[] for i in range(K): u,v,w,p=map(int,input().split()) u-=1 v-=1 edge.append((u,v,w,p)) edge_s.append((p,i)) edge_w.append((w,i)) edge_s.sort(key=lambda x:x[0]) edge_w.sort(key=lambda x:x[0]) for i in range(K-1,0,-1): e1=edge_s[i][1] e0=edge_s[i-1][1] if edge[e1][2]<=edge[e0][2]: edge_s[i-1]=edge_s[i] uf=UnionFind(N) nc=0 for _,i in edge_w: u,v,w,p=edge[i] if uf.same(u,v): continue uf.merge(u,v) nc+=w if nc>C: print(-1) exit() d=[0,K] while d[1]-d[0]>1: m=sum(d)//2 use=edge_s[m][1] uf=UnionFind(N) nc=0 u,v,w,p=edge[use] uf.merge(u,v) nc+=w for _,i in edge_w: u,v,w,p=edge[i] if uf.same(u,v): continue uf.merge(u,v) nc+=w if nc<=C: d[0]=m else: d[1]=m use=edge_s[d[0]][1] print(edge[use][3])