結果
問題 | No.1365 [Cherry 1st Tune] Whose Fault? |
ユーザー | chineristAC |
提出日時 | 2021-01-22 22:52:02 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,165 bytes |
コンパイル時間 | 319 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 104,912 KB |
最終ジャッジ日時 | 2024-06-09 06:57:41 |
合計ジャッジ時間 | 17,449 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,352 KB |
testcase_01 | AC | 41 ms
52,736 KB |
testcase_02 | AC | 41 ms
52,480 KB |
testcase_03 | RE | - |
testcase_04 | AC | 41 ms
53,248 KB |
testcase_05 | AC | 43 ms
52,992 KB |
testcase_06 | AC | 42 ms
53,632 KB |
testcase_07 | AC | 44 ms
53,632 KB |
testcase_08 | AC | 43 ms
53,632 KB |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | AC | 42 ms
52,608 KB |
testcase_12 | AC | 45 ms
53,376 KB |
testcase_13 | AC | 227 ms
79,108 KB |
testcase_14 | AC | 211 ms
79,504 KB |
testcase_15 | AC | 108 ms
77,312 KB |
testcase_16 | AC | 58 ms
69,888 KB |
testcase_17 | AC | 184 ms
78,652 KB |
testcase_18 | AC | 141 ms
77,952 KB |
testcase_19 | AC | 230 ms
79,468 KB |
testcase_20 | RE | - |
testcase_21 | AC | 202 ms
79,116 KB |
testcase_22 | AC | 196 ms
78,192 KB |
testcase_23 | AC | 289 ms
94,448 KB |
testcase_24 | AC | 459 ms
98,176 KB |
testcase_25 | AC | 599 ms
101,760 KB |
testcase_26 | AC | 494 ms
97,920 KB |
testcase_27 | AC | 526 ms
94,432 KB |
testcase_28 | AC | 371 ms
85,356 KB |
testcase_29 | AC | 352 ms
85,120 KB |
testcase_30 | AC | 683 ms
103,000 KB |
testcase_31 | AC | 640 ms
104,912 KB |
testcase_32 | AC | 459 ms
101,068 KB |
testcase_33 | AC | 582 ms
98,304 KB |
testcase_34 | AC | 502 ms
94,080 KB |
testcase_35 | AC | 450 ms
96,768 KB |
testcase_36 | AC | 569 ms
104,832 KB |
testcase_37 | AC | 289 ms
81,892 KB |
testcase_38 | AC | 251 ms
100,352 KB |
testcase_39 | AC | 667 ms
102,252 KB |
testcase_40 | AC | 654 ms
100,856 KB |
testcase_41 | AC | 569 ms
103,296 KB |
testcase_42 | RE | - |
testcase_43 | AC | 41 ms
52,608 KB |
testcase_44 | AC | 195 ms
104,192 KB |
testcase_45 | AC | 184 ms
91,736 KB |
ソースコード
class UnionFindVerSize(): def __init__(self, N,init_P,init_S): self._parent = [n for n in range(0, N)] self.P_sum = [0 for i in range(N)] for i in range(N): if init_P[i]: self.P_sum[i] = 1/init_P[i] else: self.P_sum[i] = float("inf") self.S_sum = [init_S[i] for i in range(N)] self._size = [1]*N self.group = N self.ans = 0 for i in range(N): self.ans += (self.S_sum[i]**2)/self.P_sum[i] def find_root(self, x): if self._parent[x] == x: return x self._parent[x] = self.find_root(self._parent[x]) stack = [x] while self._parent[stack[-1]]!=stack[-1]: stack.append(self._parent[stack[-1]]) for v in stack: self._parent[v] = stack[-1] return self._parent[x] def unite(self, x, y): gx = self.find_root(x) gy = self.find_root(y) if gx == gy: return self.group -= 1 if self._size[gx] >= self._size[gy]: gx,gy = gy,gx self._parent[gx] = gy self._size[gy] += self._size[gx] self.ans -= self.S_sum[gx]**2 / self.P_sum[gx] self.ans -= self.S_sum[gy]**2 / self.P_sum[gy] assert self.ans>=0 or abs(ans)<=10**-7 self.S_sum[gy] += self.S_sum[gx] self.P_sum[gy] += self.P_sum[gx] self.ans += self.S_sum[gy]**2 / self.P_sum[gy] def get_size(self, x): return self._size[self.find_root(x)] def is_same_group(self, x, y): return self.find_root(x) == self.find_root(y) import sys input = sys.stdin.readline N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) P = list(map(int,input().split())) #A = [0 for i in range(N)] #A[0] = 1 #B = [0 for i in range(N)] #P = [1 for i in range(N)] S = [A[i]-B[i] for i in range(N)] uf = UnionFindVerSize(N,P,S) ans = [] for _ in range(int(input())): x,y = map(int,input().split()) uf.unite(x-1,y-1) ans.append(uf.ans) print(*ans,sep="\n") #for i in range(len(ans)): #if ans[i] < 10**-7 and ans[i]!=0: #assert False