結果
問題 | No.1365 [Cherry 1st Tune] Whose Fault? |
ユーザー | mkawa2 |
提出日時 | 2021-11-12 01:35:27 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,139 bytes |
コンパイル時間 | 462 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 104,320 KB |
最終ジャッジ日時 | 2024-05-03 04:46:44 |
合計ジャッジ時間 | 8,222 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,224 KB |
testcase_01 | AC | 42 ms
52,096 KB |
testcase_02 | AC | 42 ms
52,352 KB |
testcase_03 | AC | 43 ms
52,992 KB |
testcase_04 | AC | 43 ms
53,504 KB |
testcase_05 | AC | 43 ms
52,864 KB |
testcase_06 | AC | 46 ms
52,992 KB |
testcase_07 | AC | 47 ms
53,632 KB |
testcase_08 | AC | 45 ms
53,120 KB |
testcase_09 | AC | 43 ms
52,736 KB |
testcase_10 | RE | - |
testcase_11 | AC | 43 ms
52,864 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 | 229 ms
78,592 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = 18446744073709551615 inf = 4294967295 md = 10**9+7 # md = 998244353 class UnionFind: def __init__(self, n, dd, ip): self.state = [-1]*n self.size_table = [1]*n self.dd = dd self.ip = ip # cntはグループ数 self.cnt = n def root(self, u): stack = [] while self.state[u] >= 0: stack.append(u) u = self.state[u] for v in stack: self.state[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u = self.root(u) v = self.root(v) if u == v: return False du = -self.state[u] dv = -self.state[v] if du < dv: u, v = v, u if du == dv: self.state[u] -= 1 self.state[v] = u self.cnt -= 1 self.size_table[u] += self.size_table[v] self.dd[u] += self.dd[v] self.ip[u] += self.ip[v] return True # グループの要素数 def size(self, u): return self.size_table[self.root(u)] def get_dp(self, u): u = self.root(u) return self.dd[u], self.ip[u] n = II() aa = LI() bb = LI() pp = LI() uf = UnionFind(n, [a-b for a, b in zip(aa, bb)], [1/p for p in pp]) s = sum(p*(a-b)**2 for a, b, p in zip(aa, bb, pp)) for _ in range(II()): x, y = LI1() if not uf.same(x, y): d, p = uf.get_dp(x) s -= d**2/p d, p = uf.get_dp(y) s -= d**2/p uf.merge(x, y) d, p = uf.get_dp(x) s += d**2/p print(s)