結果
問題 | No.1365 [Cherry 1st Tune] Whose Fault? |
ユーザー | chineristAC |
提出日時 | 2021-01-22 22:47:26 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,145 bytes |
コンパイル時間 | 880 ms |
コンパイル使用メモリ | 86,996 KB |
実行使用メモリ | 109,416 KB |
最終ジャッジ日時 | 2023-08-28 11:29:17 |
合計ジャッジ時間 | 20,900 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,360 KB |
testcase_01 | AC | 73 ms
71,060 KB |
testcase_02 | AC | 75 ms
71,340 KB |
testcase_03 | RE | - |
testcase_04 | AC | 73 ms
71,112 KB |
testcase_05 | AC | 75 ms
71,396 KB |
testcase_06 | AC | 76 ms
71,416 KB |
testcase_07 | AC | 77 ms
71,488 KB |
testcase_08 | AC | 73 ms
71,496 KB |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | AC | 74 ms
71,364 KB |
testcase_12 | AC | 75 ms
71,328 KB |
testcase_13 | AC | 250 ms
81,612 KB |
testcase_14 | AC | 238 ms
81,000 KB |
testcase_15 | AC | 126 ms
78,168 KB |
testcase_16 | AC | 91 ms
76,812 KB |
testcase_17 | AC | 219 ms
80,040 KB |
testcase_18 | AC | 160 ms
79,496 KB |
testcase_19 | AC | 254 ms
81,848 KB |
testcase_20 | RE | - |
testcase_21 | AC | 235 ms
80,648 KB |
testcase_22 | AC | 221 ms
80,924 KB |
testcase_23 | AC | 321 ms
94,216 KB |
testcase_24 | AC | 489 ms
95,144 KB |
testcase_25 | AC | 648 ms
103,804 KB |
testcase_26 | AC | 520 ms
96,296 KB |
testcase_27 | AC | 552 ms
95,360 KB |
testcase_28 | AC | 392 ms
86,852 KB |
testcase_29 | AC | 388 ms
87,088 KB |
testcase_30 | AC | 734 ms
109,416 KB |
testcase_31 | AC | 688 ms
107,084 KB |
testcase_32 | AC | 517 ms
99,484 KB |
testcase_33 | AC | 627 ms
100,144 KB |
testcase_34 | AC | 546 ms
95,560 KB |
testcase_35 | AC | 482 ms
94,976 KB |
testcase_36 | AC | 629 ms
105,296 KB |
testcase_37 | AC | 335 ms
84,020 KB |
testcase_38 | AC | 275 ms
98,324 KB |
testcase_39 | AC | 705 ms
106,948 KB |
testcase_40 | AC | 686 ms
105,364 KB |
testcase_41 | AC | 596 ms
102,496 KB |
testcase_42 | RE | - |
testcase_43 | AC | 73 ms
71,520 KB |
testcase_44 | AC | 214 ms
101,860 KB |
testcase_45 | AC | 209 ms
90,924 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 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