結果
問題 | No.2494 Sum within Components |
ユーザー | Mottchan |
提出日時 | 2023-10-07 00:05:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 382 ms / 2,000 ms |
コード長 | 2,085 bytes |
コンパイル時間 | 261 ms |
コンパイル使用メモリ | 82,524 KB |
実行使用メモリ | 136,088 KB |
最終ジャッジ日時 | 2024-07-26 17:29:16 |
合計ジャッジ時間 | 3,785 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
55,860 KB |
testcase_01 | AC | 40 ms
55,536 KB |
testcase_02 | AC | 41 ms
54,924 KB |
testcase_03 | AC | 41 ms
54,892 KB |
testcase_04 | AC | 40 ms
55,836 KB |
testcase_05 | AC | 41 ms
55,208 KB |
testcase_06 | AC | 41 ms
56,636 KB |
testcase_07 | AC | 41 ms
55,684 KB |
testcase_08 | AC | 42 ms
55,188 KB |
testcase_09 | AC | 102 ms
78,148 KB |
testcase_10 | AC | 121 ms
81,576 KB |
testcase_11 | AC | 75 ms
78,240 KB |
testcase_12 | AC | 140 ms
81,016 KB |
testcase_13 | AC | 126 ms
80,312 KB |
testcase_14 | AC | 318 ms
112,720 KB |
testcase_15 | AC | 321 ms
113,784 KB |
testcase_16 | AC | 178 ms
103,292 KB |
testcase_17 | AC | 142 ms
135,752 KB |
testcase_18 | AC | 178 ms
133,596 KB |
testcase_19 | AC | 382 ms
136,088 KB |
ソースコード
import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd from itertools import product, permutations #重複あり:list(product(list('123'),repeat = 2)),重複なし:list(permutations(list('123'))) MOD = 998244353 class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def group(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return ''.join(f'{r}: {m}' for r, m in self.group().items()) n,m = map(int,input().split()) l = list(map(int,input().split())) uf = UnionFind(n) graph = [[] for i in range(n+1)] e=[] for i in range(m): a,b = map(int,input().split()) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) e.append([a,b]) uf.union(a,b) d = defaultdict(int) for i in range(n): ii = uf.find(i) d[ii] += l[i] d[ii] %= MOD ans = 1 for i in range(n): ii = uf.find(i) ans *= d[ii] ans %= MOD print(ans)