結果
問題 | No.1365 [Cherry 1st Tune] Whose Fault? |
ユーザー | chineristAC |
提出日時 | 2021-01-22 21:47:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 786 ms / 2,000 ms |
コード長 | 2,130 bytes |
コンパイル時間 | 928 ms |
コンパイル使用メモリ | 86,836 KB |
実行使用メモリ | 110,880 KB |
最終ジャッジ日時 | 2023-08-28 11:22:53 |
合計ジャッジ時間 | 21,334 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 82 ms
71,344 KB |
testcase_01 | AC | 74 ms
71,240 KB |
testcase_02 | AC | 75 ms
71,300 KB |
testcase_03 | AC | 73 ms
71,424 KB |
testcase_04 | AC | 72 ms
71,272 KB |
testcase_05 | AC | 81 ms
71,484 KB |
testcase_06 | AC | 79 ms
71,212 KB |
testcase_07 | AC | 76 ms
71,332 KB |
testcase_08 | AC | 72 ms
71,484 KB |
testcase_09 | AC | 72 ms
71,516 KB |
testcase_10 | AC | 74 ms
71,432 KB |
testcase_11 | AC | 72 ms
71,328 KB |
testcase_12 | AC | 75 ms
71,332 KB |
testcase_13 | AC | 270 ms
82,304 KB |
testcase_14 | AC | 239 ms
82,040 KB |
testcase_15 | AC | 129 ms
78,156 KB |
testcase_16 | AC | 88 ms
76,864 KB |
testcase_17 | AC | 213 ms
81,064 KB |
testcase_18 | AC | 176 ms
79,924 KB |
testcase_19 | AC | 252 ms
81,092 KB |
testcase_20 | AC | 155 ms
79,108 KB |
testcase_21 | AC | 255 ms
81,952 KB |
testcase_22 | AC | 219 ms
81,160 KB |
testcase_23 | AC | 357 ms
93,500 KB |
testcase_24 | AC | 533 ms
95,388 KB |
testcase_25 | AC | 665 ms
102,904 KB |
testcase_26 | AC | 564 ms
96,316 KB |
testcase_27 | AC | 571 ms
96,056 KB |
testcase_28 | AC | 389 ms
85,732 KB |
testcase_29 | AC | 411 ms
87,328 KB |
testcase_30 | AC | 786 ms
110,880 KB |
testcase_31 | AC | 731 ms
107,860 KB |
testcase_32 | AC | 585 ms
99,564 KB |
testcase_33 | AC | 662 ms
100,368 KB |
testcase_34 | AC | 578 ms
97,420 KB |
testcase_35 | AC | 498 ms
95,404 KB |
testcase_36 | AC | 687 ms
105,164 KB |
testcase_37 | AC | 357 ms
84,220 KB |
testcase_38 | AC | 291 ms
98,288 KB |
testcase_39 | AC | 731 ms
107,044 KB |
testcase_40 | AC | 759 ms
106,228 KB |
testcase_41 | AC | 684 ms
104,024 KB |
testcase_42 | AC | 563 ms
95,452 KB |
testcase_43 | AC | 72 ms
71,432 KB |
testcase_44 | AC | 224 ms
101,500 KB |
testcase_45 | AC | 217 ms
91,192 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] 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): if self.P_sum[i]!=0: 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] if self.P_sum[gx]!=0: self.ans -= self.S_sum[gx]**2 / self.P_sum[gx] if self.P_sum[gy]!=0: self.ans -= self.S_sum[gy]**2 / self.P_sum[gy] self.S_sum[gy] += self.S_sum[gx] if self.P_sum[gx]!=0 and self.P_sum[gy]!=0: self.P_sum[gy] += self.P_sum[gx] elif self.P_sum[gx]==0: self.P_sum[gy] = 0 if self.P_sum[gy]!=0: 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())) 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")