結果
問題 | No.1365 [Cherry 1st Tune] Whose Fault? |
ユーザー | 👑 Kazun |
提出日時 | 2021-01-17 02:38:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 639 ms / 2,000 ms |
コード長 | 3,469 bytes |
コンパイル時間 | 466 ms |
コンパイル使用メモリ | 87,156 KB |
実行使用メモリ | 115,092 KB |
最終ジャッジ日時 | 2023-08-28 11:15:42 |
合計ジャッジ時間 | 18,415 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,268 KB |
testcase_01 | AC | 75 ms
71,448 KB |
testcase_02 | AC | 75 ms
71,608 KB |
testcase_03 | AC | 77 ms
71,604 KB |
testcase_04 | AC | 74 ms
71,440 KB |
testcase_05 | AC | 75 ms
71,572 KB |
testcase_06 | AC | 75 ms
71,444 KB |
testcase_07 | AC | 74 ms
71,288 KB |
testcase_08 | AC | 72 ms
71,444 KB |
testcase_09 | AC | 73 ms
71,604 KB |
testcase_10 | AC | 72 ms
71,320 KB |
testcase_11 | AC | 74 ms
71,432 KB |
testcase_12 | AC | 75 ms
71,452 KB |
testcase_13 | AC | 229 ms
82,056 KB |
testcase_14 | AC | 215 ms
82,192 KB |
testcase_15 | AC | 129 ms
79,548 KB |
testcase_16 | AC | 96 ms
79,272 KB |
testcase_17 | AC | 203 ms
80,808 KB |
testcase_18 | AC | 188 ms
82,012 KB |
testcase_19 | AC | 222 ms
82,900 KB |
testcase_20 | AC | 161 ms
79,704 KB |
testcase_21 | AC | 218 ms
82,612 KB |
testcase_22 | AC | 202 ms
80,680 KB |
testcase_23 | AC | 310 ms
95,276 KB |
testcase_24 | AC | 450 ms
102,792 KB |
testcase_25 | AC | 604 ms
110,008 KB |
testcase_26 | AC | 501 ms
103,640 KB |
testcase_27 | AC | 466 ms
95,624 KB |
testcase_28 | AC | 317 ms
87,296 KB |
testcase_29 | AC | 310 ms
89,372 KB |
testcase_30 | AC | 639 ms
114,500 KB |
testcase_31 | AC | 639 ms
115,092 KB |
testcase_32 | AC | 491 ms
108,864 KB |
testcase_33 | AC | 540 ms
103,704 KB |
testcase_34 | AC | 476 ms
99,804 KB |
testcase_35 | AC | 400 ms
103,548 KB |
testcase_36 | AC | 566 ms
110,852 KB |
testcase_37 | AC | 291 ms
87,580 KB |
testcase_38 | AC | 311 ms
102,216 KB |
testcase_39 | AC | 613 ms
111,752 KB |
testcase_40 | AC | 630 ms
110,404 KB |
testcase_41 | AC | 587 ms
110,244 KB |
testcase_42 | AC | 504 ms
95,620 KB |
testcase_43 | AC | 73 ms
71,516 KB |
testcase_44 | AC | 307 ms
109,548 KB |
testcase_45 | AC | 181 ms
81,292 KB |
ソースコード
class Coloring_Union_Find(): def __init__(self,N,f,e=0): """0,1,...,n-1を要素として初期化する. N:要素数 f:2変数関数の合成 e:最初の値 """ self.n=N self.parents=[-1]*N self.data=[e]*N self.rank=[0]*N self.f=f def find(self, x): """要素xの属している族を調べる. x:要素 """ V=[] while self.parents[x]>=0: V.append(x) x=self.parents[x] for v in V: self.parents[v]=x return x def union(self, x, y): """要素x,yを同一視する. x,y:要素 """ x=self.find(x) y=self.find(y) if x==y: return self.data[x]=self.data[y]=self.f(self.data[x],self.data[y]) if self.rank[x]<self.rank[y]: x,y=y,x self.parents[x]+=self.parents[y] self.parents[y]=x if self.rank[x]==self.rank[y]: self.rank[x]+=1 def size(self, x): """要素xの属している要素の数. x:要素 """ return -self.parents[self.find(x)] def same(self, x, y): """要素x,yは同一視されているか? x,y:要素 """ return self.find(x) == self.find(y) def set(self,x,c): """要素xの属する成分の色をcに変更する. x:要素 c:色 """ self.data[self.find(x)]=c return def look(self,x): """要素xの属する成分の色 x:要素 """ return self.data[self.find(x)] def members(self, x): """要素xが属している族の要素. ※族の要素の個数が欲しいときはsizeを使うこと!! 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): """全ての族の出力 """ X={r:[] for r in self.roots()} for k in range(self.n): X[self.find(k)].append(k) return X def color_list(self): return [self.look(x) for x in range(self.n)] def color_map(self): return {x:self.look(x) for x in self.roots()} def __str__(self): return '\n'.join('{} [color:{}]: {}'.format(r,self.look(r),self.members(r)) for r in self.roots()) def __repr__(self): return self.__str__() #================================================ import sys input=sys.stdin.readline write=sys.stdout.write N=int(input()) A=["*"]+list(map(int,input().split())) B=["*"]+list(map(int,input().split())) P=["*"]+list(map(int,input().split())) inf=float("inf") U=Coloring_Union_Find(N+1,lambda x,y:[x[0]+y[0],x[1]+y[1]],[0,0]) Ans=0 for i in range(1,N+1): d=A[i]-B[i] Ans+=d*d*P[i] if P[i]: U.set(i,[d,1/P[i]]) else: U.set(i,[d,inf]) Q=int(input()) S=[0]*Q for q in range(Q): X,Y=map(int,input().split()) if not U.same(X,Y): d,p=U.look(X) Ans-=d*d/p d,p=U.look(Y) Ans-=d*d/p U.union(X,Y) d,p=U.look(X) Ans+=d*d/p S[q]=Ans write("\n".join(map(str,S)))