結果

問題 No.1365 [Cherry 1st Tune] Whose Fault?
ユーザー convexineqconvexineq
提出日時 2021-01-23 13:57:03
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,519 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 115,920 KB
最終ジャッジ日時 2023-08-29 00:38:26
合計ジャッジ時間 11,581 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,372 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
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 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n)) #親ノード
        self.size = [1]*n #グループの要素数
 
    def root(self, x): #root(x): xの根ノードを返す.
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる
        x, y = self.root(x), self.root(y)
        if x == y: return False
        if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue
        return self.root(x) == self.root(y)
        
    def getsize(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]

n = int(input())
*a, = map(int,input().split())
*b, = map(int,input().split())
*p, = map(float,input().split())

d = [ai-bi for ai,bi in zip(a,b)]
UF = UnionFind(n)
q = int(input())
ans = sum(pi*di**2 for pi,di in zip(p,d))
for _ in range(n):
    x,y = map(int,input().split())
    x -= 1; y -= 1
    rx,ry = UF.root(x), UF.root(y)
    if rx != ry:
        ans -= p[rx]*d[rx]**2 + p[ry]*d[ry]**2
        UF.merge(rx,ry)
        nr = UF.root(rx)
        p[nr] = 1/(1/p[rx]+1/p[ry])
        d[nr] = d[rx]+d[ry]
        ans += p[nr]*d[nr]**2
    print(ans)
0