結果
問題 | No.2494 Sum within Components |
ユーザー |
|
提出日時 | 2023-10-07 00:05:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 487 ms / 2,000 ms |
コード長 | 2,085 bytes |
コンパイル時間 | 406 ms |
コンパイル使用メモリ | 87,348 KB |
実行使用メモリ | 128,004 KB |
最終ジャッジ日時 | 2023-10-07 00:06:04 |
合計ジャッジ時間 | 5,974 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 94 ms
72,024 KB |
testcase_01 | AC | 91 ms
71,640 KB |
testcase_02 | AC | 93 ms
72,084 KB |
testcase_03 | AC | 93 ms
71,756 KB |
testcase_04 | AC | 92 ms
71,836 KB |
testcase_05 | AC | 91 ms
72,000 KB |
testcase_06 | AC | 91 ms
71,588 KB |
testcase_07 | AC | 93 ms
72,012 KB |
testcase_08 | AC | 93 ms
71,480 KB |
testcase_09 | AC | 161 ms
79,996 KB |
testcase_10 | AC | 183 ms
82,960 KB |
testcase_11 | AC | 125 ms
78,344 KB |
testcase_12 | AC | 210 ms
83,016 KB |
testcase_13 | AC | 191 ms
82,232 KB |
testcase_14 | AC | 446 ms
117,380 KB |
testcase_15 | AC | 434 ms
116,440 KB |
testcase_16 | AC | 254 ms
110,132 KB |
testcase_17 | AC | 194 ms
123,912 KB |
testcase_18 | AC | 272 ms
126,436 KB |
testcase_19 | AC | 487 ms
128,004 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)