結果

問題 No.1365 [Cherry 1st Tune] Whose Fault?
ユーザー chineristACchineristAC
提出日時 2021-01-22 23:05:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 129,176 KB
最終ジャッジ日時 2023-08-28 11:37:52
合計ジャッジ時間 16,642 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,364 KB
testcase_01 AC 73 ms
71,316 KB
testcase_02 AC 74 ms
71,452 KB
testcase_03 AC 75 ms
71,588 KB
testcase_04 AC 73 ms
71,660 KB
testcase_05 AC 73 ms
71,372 KB
testcase_06 AC 73 ms
71,144 KB
testcase_07 AC 74 ms
71,364 KB
testcase_08 AC 76 ms
71,352 KB
testcase_09 AC 73 ms
71,600 KB
testcase_10 AC 73 ms
71,664 KB
testcase_11 AC 73 ms
71,292 KB
testcase_12 AC 73 ms
71,484 KB
testcase_13 AC 150 ms
81,568 KB
testcase_14 AC 143 ms
81,396 KB
testcase_15 AC 117 ms
79,040 KB
testcase_16 AC 91 ms
76,940 KB
testcase_17 AC 136 ms
79,500 KB
testcase_18 AC 125 ms
80,564 KB
testcase_19 AC 152 ms
81,336 KB
testcase_20 AC 139 ms
78,776 KB
testcase_21 AC 149 ms
81,592 KB
testcase_22 AC 141 ms
79,372 KB
testcase_23 AC 225 ms
98,212 KB
testcase_24 AC 326 ms
112,700 KB
testcase_25 AC 459 ms
121,164 KB
testcase_26 AC 434 ms
109,372 KB
testcase_27 AC 349 ms
96,216 KB
testcase_28 AC 233 ms
87,264 KB
testcase_29 AC 216 ms
91,360 KB
testcase_30 AC 547 ms
124,268 KB
testcase_31 AC 517 ms
128,512 KB
testcase_32 AC 393 ms
120,304 KB
testcase_33 AC 428 ms
106,188 KB
testcase_34 AC 358 ms
101,380 KB
testcase_35 AC 315 ms
112,372 KB
testcase_36 AC 469 ms
125,608 KB
testcase_37 AC 187 ms
86,912 KB
testcase_38 AC 245 ms
106,500 KB
testcase_39 AC 490 ms
119,696 KB
testcase_40 AC 485 ms
117,188 KB
testcase_41 AC 442 ms
120,008 KB
testcase_42 AC 371 ms
95,944 KB
testcase_43 AC 74 ms
71,360 KB
testcase_44 AC 258 ms
129,176 KB
testcase_45 AC 171 ms
89,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)]
for i in range(N):
    if P[i]:
        P[i] = 1/P[i]
    else:
        P[i] = float("inf")

ans = 0
for i in range(N):
    ans += S[i]**2 / P[i]

parent = [i for i in range(N)]
g = [set([i]) for i in range(N)]

def unite(x,y):
    global ans
    if parent[x]==parent[y]:
        return

    gx,gy = parent[x],parent[y]
    if len(g[gy]) > len(g[gx]):
        gx,gy = gy,gx

    ans -= S[gx]**2 / P[gx]
    ans -= S[gy]**2 / P[gy]

    S[gx] += S[gy]
    P[gx] += P[gy]

    ans += S[gx]**2 / P[gx]

    for v in g[gy]:
        parent[v] = gx
        g[gx].add(v)

    g[gy] = []


res = []
for _ in range(int(input())):
    x,y = map(int,input().split())
    unite(x-1,y-1)
    res.append(ans)

print(*res,sep="\n")
0