結果
問題 | No.1365 [Cherry 1st Tune] Whose Fault? |
ユーザー | mkawa2 |
提出日時 | 2021-11-12 01:42:10 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 975 ms / 2,000 ms |
コード長 | 2,287 bytes |
コンパイル時間 | 195 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 103,680 KB |
最終ジャッジ日時 | 2024-11-24 02:09:38 |
合計ジャッジ時間 | 22,764 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
52,096 KB |
testcase_01 | AC | 48 ms
52,096 KB |
testcase_02 | AC | 49 ms
52,352 KB |
testcase_03 | AC | 51 ms
52,736 KB |
testcase_04 | AC | 51 ms
52,992 KB |
testcase_05 | AC | 51 ms
52,864 KB |
testcase_06 | AC | 52 ms
52,992 KB |
testcase_07 | AC | 54 ms
53,760 KB |
testcase_08 | AC | 56 ms
53,504 KB |
testcase_09 | AC | 55 ms
52,864 KB |
testcase_10 | AC | 54 ms
52,992 KB |
testcase_11 | AC | 54 ms
52,992 KB |
testcase_12 | AC | 57 ms
53,504 KB |
testcase_13 | AC | 351 ms
79,572 KB |
testcase_14 | AC | 317 ms
79,936 KB |
testcase_15 | AC | 148 ms
77,824 KB |
testcase_16 | AC | 95 ms
76,672 KB |
testcase_17 | AC | 296 ms
80,076 KB |
testcase_18 | AC | 233 ms
78,932 KB |
testcase_19 | AC | 320 ms
79,908 KB |
testcase_20 | AC | 188 ms
77,056 KB |
testcase_21 | AC | 311 ms
79,704 KB |
testcase_22 | AC | 254 ms
78,336 KB |
testcase_23 | AC | 488 ms
94,848 KB |
testcase_24 | AC | 654 ms
94,848 KB |
testcase_25 | AC | 880 ms
98,816 KB |
testcase_26 | AC | 713 ms
98,816 KB |
testcase_27 | AC | 701 ms
87,552 KB |
testcase_28 | AC | 491 ms
81,536 KB |
testcase_29 | AC | 535 ms
84,864 KB |
testcase_30 | AC | 975 ms
102,784 KB |
testcase_31 | AC | 958 ms
102,912 KB |
testcase_32 | AC | 751 ms
100,992 KB |
testcase_33 | AC | 874 ms
94,336 KB |
testcase_34 | AC | 723 ms
93,312 KB |
testcase_35 | AC | 629 ms
95,488 KB |
testcase_36 | AC | 863 ms
103,680 KB |
testcase_37 | AC | 430 ms
82,816 KB |
testcase_38 | AC | 446 ms
99,072 KB |
testcase_39 | AC | 930 ms
95,360 KB |
testcase_40 | AC | 921 ms
94,976 KB |
testcase_41 | AC | 852 ms
102,528 KB |
testcase_42 | AC | 711 ms
84,608 KB |
testcase_43 | AC | 49 ms
51,968 KB |
testcase_44 | AC | 327 ms
103,296 KB |
testcase_45 | AC | 288 ms
77,952 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] if self.ip[u] == inf or self.ip[v] == inf: self.ip[u] = inf else: 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 if p else inf 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) if p < inf: s -= d**2/p d, p = uf.get_dp(y) if p < inf: s -= d**2/p uf.merge(x, y) d, p = uf.get_dp(x) if p < inf: s += d**2/p print(s)