結果
問題 | No.2642 Don't cut line! |
ユーザー | pitP |
提出日時 | 2024-02-20 02:02:44 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,412 bytes |
コンパイル時間 | 506 ms |
コンパイル使用メモリ | 82,200 KB |
実行使用メモリ | 849,408 KB |
最終ジャッジ日時 | 2024-09-29 03:21:59 |
合計ジャッジ時間 | 5,920 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | MLE | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
ソースコード
# https://yukicoder.me/submissions/953174 class UF: def __init__(self,n): self.p = [-1]*n def f(self,x): if self.p[x]<0: return x else: self.p[x] = self.f(self.p[x]); return self.p[x] def u(self,x,y): x = self.f(x); y = self.f(y) if x==y: return if -self.p[x]<-self.p[y]: x,y = y,x self.p[x] += self.p[y]; self.p[y] = x def s(self,x,y): return self.f(x) == self.f(y) class DoublingLCA: def __init__(self,n,adj,root=0): self.logn = n.bit_length() self.ancestor,self.depth,self.weight = [[-1]*(n+1) for _ in range(self.logn)],[-1]*n,[[0]*(n+1) for _ in range(self.logn)] stack = [(root,-1,0)] while stack: v,p,dep = stack.pop() self.ancestor[0][v],self.depth[v] = p,dep for c,w in adj[v]: if c!=p: stack.append((c,v,dep+1)) self.weight[0][c] = max(self.weight[0][c],w) for i in range(max(self.depth).bit_length()-1): for j in range(len(self.ancestor[i])): v = self.ancestor[i][j] u = self.ancestor[i][v] self.ancestor[i+1][j] = u self.weight[i+1][j] = max(self.weight[i][u],self.weight[i][v]) def get_kth_ancestor(self,v,k): w = 0 for i in range(k.bit_length()): if k>>i&1: v = self.ancestor[i][v] w = max(w,self.weight[i][v]) return v,w def get_max_weight(self,u,v): depu,depv = self.depth[u],self.depth[v] if depu>depv: u,v,depu,depv = v,u,depv,depu v,w = self.get_kth_ancestor(v,depv-depu) if u==v: return w for k in range(depu.bit_length()-1,-1,-1): nu,nv = self.ancestor[k][u],self.ancestor[k][v] w = max(w,self.weight[k][u],self.weight[k][v]) if nu!=nv: u,v = nu,nv return w n,k,c = map(int,input().split()) wpuv = [(-1, -1, -1, -1) for _ in range(k)] for i in range(k): u,v,w,p = map(int,input().split()) wpuv[i] = (w,p,u-1,v-1) uf = UF(n); d = m = 0; adj = [[] for _ in range(n)] for w,p,u,v in sorted(wpuv): if uf.s(u,v): continue uf.u(u,v); d += w; m = max(m,p) adj[u-1].append((v,w)); adj[v-1].append((u,w)) if d>c: exit(print(-1)) lca = DoublingLCA(n,adj) for w,p,u,v in wpuv: if d-lca.get_max_weight(u,v)+w<=c: m = max(m,p) print(m)