結果
問題 | No.1365 [Cherry 1st Tune] Whose Fault? |
ユーザー | 👑 Kazun |
提出日時 | 2021-01-17 02:33:16 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 633 ms / 2,000 ms |
コード長 | 3,469 bytes |
コンパイル時間 | 346 ms |
コンパイル使用メモリ | 87,156 KB |
実行使用メモリ | 114,728 KB |
最終ジャッジ日時 | 2023-08-28 11:14:54 |
合計ジャッジ時間 | 17,420 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 72 ms
71,164 KB |
testcase_01 | AC | 74 ms
71,248 KB |
testcase_02 | AC | 73 ms
71,124 KB |
testcase_03 | AC | 75 ms
71,396 KB |
testcase_04 | AC | 75 ms
71,160 KB |
testcase_05 | AC | 74 ms
71,356 KB |
testcase_06 | AC | 75 ms
71,248 KB |
testcase_07 | AC | 74 ms
71,392 KB |
testcase_08 | AC | 75 ms
71,380 KB |
testcase_09 | AC | 74 ms
71,428 KB |
testcase_10 | AC | 74 ms
71,376 KB |
testcase_11 | AC | 73 ms
71,240 KB |
testcase_12 | AC | 76 ms
71,156 KB |
testcase_13 | AC | 219 ms
81,668 KB |
testcase_14 | AC | 211 ms
81,980 KB |
testcase_15 | AC | 127 ms
79,164 KB |
testcase_16 | AC | 94 ms
78,812 KB |
testcase_17 | AC | 201 ms
80,556 KB |
testcase_18 | AC | 192 ms
81,676 KB |
testcase_19 | AC | 224 ms
82,480 KB |
testcase_20 | AC | 161 ms
79,452 KB |
testcase_21 | AC | 211 ms
82,364 KB |
testcase_22 | AC | 196 ms
80,176 KB |
testcase_23 | AC | 307 ms
95,344 KB |
testcase_24 | AC | 427 ms
102,796 KB |
testcase_25 | AC | 559 ms
109,836 KB |
testcase_26 | AC | 484 ms
103,508 KB |
testcase_27 | AC | 456 ms
95,268 KB |
testcase_28 | AC | 313 ms
87,144 KB |
testcase_29 | AC | 309 ms
89,032 KB |
testcase_30 | AC | 633 ms
114,436 KB |
testcase_31 | AC | 630 ms
114,728 KB |
testcase_32 | AC | 479 ms
108,544 KB |
testcase_33 | AC | 523 ms
103,544 KB |
testcase_34 | AC | 459 ms
99,632 KB |
testcase_35 | AC | 399 ms
103,324 KB |
testcase_36 | AC | 554 ms
110,384 KB |
testcase_37 | AC | 282 ms
87,336 KB |
testcase_38 | AC | 306 ms
101,956 KB |
testcase_39 | AC | 591 ms
110,792 KB |
testcase_40 | AC | 617 ms
110,480 KB |
testcase_41 | AC | 559 ms
110,112 KB |
testcase_42 | AC | 475 ms
95,420 KB |
testcase_43 | AC | 73 ms
71,248 KB |
testcase_44 | AC | 291 ms
109,440 KB |
testcase_45 | AC | 172 ms
81,040 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)))