結果
問題 | No.828 全方位神童数 |
ユーザー | maspy |
提出日時 | 2020-04-16 16:41:14 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,369 ms / 2,000 ms |
コード長 | 1,505 bytes |
コンパイル時間 | 372 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 74,072 KB |
最終ジャッジ日時 | 2024-10-01 20:04:07 |
合計ジャッジ時間 | 30,783 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,752 KB |
testcase_01 | AC | 31 ms
10,752 KB |
testcase_02 | AC | 31 ms
10,880 KB |
testcase_03 | AC | 80 ms
14,592 KB |
testcase_04 | AC | 42 ms
11,776 KB |
testcase_05 | AC | 73 ms
13,952 KB |
testcase_06 | AC | 40 ms
11,520 KB |
testcase_07 | AC | 36 ms
11,392 KB |
testcase_08 | AC | 40 ms
11,520 KB |
testcase_09 | AC | 34 ms
11,136 KB |
testcase_10 | AC | 62 ms
13,568 KB |
testcase_11 | AC | 35 ms
11,136 KB |
testcase_12 | AC | 64 ms
13,568 KB |
testcase_13 | AC | 464 ms
33,756 KB |
testcase_14 | AC | 977 ms
59,716 KB |
testcase_15 | AC | 341 ms
28,428 KB |
testcase_16 | AC | 491 ms
34,852 KB |
testcase_17 | AC | 373 ms
29,760 KB |
testcase_18 | AC | 702 ms
44,528 KB |
testcase_19 | AC | 1,232 ms
68,772 KB |
testcase_20 | AC | 803 ms
50,636 KB |
testcase_21 | AC | 1,056 ms
61,488 KB |
testcase_22 | AC | 247 ms
23,504 KB |
testcase_23 | AC | 91 ms
15,744 KB |
testcase_24 | AC | 663 ms
43,040 KB |
testcase_25 | AC | 263 ms
24,012 KB |
testcase_26 | AC | 1,237 ms
68,656 KB |
testcase_27 | AC | 1,041 ms
60,492 KB |
testcase_28 | AC | 1,230 ms
69,008 KB |
testcase_29 | AC | 1,154 ms
65,984 KB |
testcase_30 | AC | 650 ms
42,972 KB |
testcase_31 | AC | 631 ms
42,088 KB |
testcase_32 | AC | 1,222 ms
68,492 KB |
testcase_33 | AC | 1,352 ms
73,436 KB |
testcase_34 | AC | 1,050 ms
61,076 KB |
testcase_35 | AC | 701 ms
44,812 KB |
testcase_36 | AC | 883 ms
52,804 KB |
testcase_37 | AC | 569 ms
38,652 KB |
testcase_38 | AC | 787 ms
48,896 KB |
testcase_39 | AC | 1,231 ms
69,044 KB |
testcase_40 | AC | 565 ms
38,660 KB |
testcase_41 | AC | 478 ms
34,112 KB |
testcase_42 | AC | 1,369 ms
74,072 KB |
testcase_43 | AC | 739 ms
65,472 KB |
testcase_44 | AC | 300 ms
32,168 KB |
testcase_45 | AC | 443 ms
42,916 KB |
ソースコード
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10 ** 9 + 7 N = int(readline()) R = tuple(map(int, readline().split())) class UnionFind: def __init__(self, N): self.root = list(range(N)) self.size = [1] * (N) self.largest = list(range(N)) def find_root(self, x): root = self.root while root[x] != x: root[x] = root[root[x]] x = root[x] return x def merge(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return False sx, sy = self.size[x], self.size[y] v = max(self.largest[x], self.largest[y]) if sx < sy: self.root[x] = y self.size[y] += sx self.largest[y] = v else: self.root[y] = x self.size[x] += sy self.largest[x] = v return True graph = [[] for _ in range(N + 1)] m = map(int, read().split()) for u, v in zip(m, m): graph[u].append(v) graph[v].append(u) parent = [0] * (N + 1) uf = UnionFind(N + 1) merge = uf.merge find = uf.find_root for v in range(1, N + 1): child = set(uf.largest[find(w)] for w in graph[v] if w < v) for w in child: merge(v, w) parent[w] = v S = [1] * (N + 1) for i in range(N - 1, 0, -1): S[i] += S[parent[i]] answer = 1 for r, s in zip(R, S[1:]): answer *= (r + s) answer %= MOD print(answer)