結果

問題 No.1365 [Cherry 1st Tune] Whose Fault?
ユーザー chineristACchineristAC
提出日時 2021-01-22 21:40:30
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,784 bytes
コンパイル時間 1,031 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 101,920 KB
最終ジャッジ日時 2023-08-28 11:21:38
合計ジャッジ時間 10,289 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,204 KB
testcase_01 AC 71 ms
71,272 KB
testcase_02 AC 71 ms
71,304 KB
testcase_03 AC 71 ms
71,316 KB
testcase_04 AC 72 ms
71,160 KB
testcase_05 AC 71 ms
71,164 KB
testcase_06 AC 75 ms
71,276 KB
testcase_07 AC 73 ms
71,272 KB
testcase_08 AC 72 ms
71,312 KB
testcase_09 AC 72 ms
71,164 KB
testcase_10 RE -
testcase_11 AC 71 ms
71,080 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 AC 208 ms
91,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFindVerSize():
    def __init__(self, N,init_P,init_S):
        self._parent = [n for n in range(0, N)]
        self.P_sum = [1/init_P[i] for i in range(N)]
        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]

        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()))

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")
0