結果
問題 | No.2642 Don't cut line! |
ユーザー | こめだわら |
提出日時 | 2024-02-19 22:37:54 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,026 bytes |
コンパイル時間 | 242 ms |
コンパイル使用メモリ | 82,420 KB |
実行使用メモリ | 120,212 KB |
最終ジャッジ日時 | 2024-09-29 02:30:34 |
合計ジャッジ時間 | 53,134 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,900 KB |
testcase_01 | AC | 1,619 ms
119,584 KB |
testcase_02 | AC | 1,638 ms
119,716 KB |
testcase_03 | AC | 1,644 ms
120,212 KB |
testcase_04 | AC | 1,652 ms
119,676 KB |
testcase_05 | AC | 1,660 ms
119,808 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 | 566 ms
104,800 KB |
testcase_17 | AC | 1,458 ms
113,472 KB |
testcase_18 | AC | 1,547 ms
115,396 KB |
testcase_19 | AC | 1,077 ms
104,496 KB |
testcase_20 | AC | 1,312 ms
99,116 KB |
testcase_21 | AC | 457 ms
100,252 KB |
testcase_22 | AC | 412 ms
99,820 KB |
testcase_23 | AC | 1,721 ms
119,148 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 1,299 ms
102,428 KB |
testcase_28 | AC | 2,007 ms
114,160 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 1,679 ms
107,184 KB |
testcase_32 | WA | - |
testcase_33 | AC | 42 ms
54,048 KB |
testcase_34 | AC | 40 ms
54,096 KB |
testcase_35 | AC | 39 ms
53,044 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]) 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])