結果
問題 | No.2494 Sum within Components |
ユーザー | titia |
提出日時 | 2023-10-06 21:48:22 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 892 ms / 2,000 ms |
コード長 | 825 bytes |
コンパイル時間 | 901 ms |
コンパイル使用メモリ | 10,780 KB |
実行使用メモリ | 33,264 KB |
最終ジャッジ日時 | 2023-10-06 21:48:28 |
合計ジャッジ時間 | 5,207 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
7,948 KB |
testcase_01 | AC | 16 ms
7,780 KB |
testcase_02 | AC | 16 ms
7,808 KB |
testcase_03 | AC | 16 ms
7,808 KB |
testcase_04 | AC | 16 ms
7,820 KB |
testcase_05 | AC | 16 ms
7,832 KB |
testcase_06 | AC | 16 ms
7,860 KB |
testcase_07 | AC | 17 ms
7,820 KB |
testcase_08 | AC | 17 ms
7,816 KB |
testcase_09 | AC | 78 ms
8,848 KB |
testcase_10 | AC | 77 ms
10,876 KB |
testcase_11 | AC | 34 ms
9,424 KB |
testcase_12 | AC | 104 ms
10,652 KB |
testcase_13 | AC | 69 ms
10,452 KB |
testcase_14 | AC | 754 ms
23,112 KB |
testcase_15 | AC | 824 ms
18,940 KB |
testcase_16 | AC | 301 ms
23,584 KB |
testcase_17 | AC | 214 ms
33,244 KB |
testcase_18 | AC | 300 ms
33,264 KB |
testcase_19 | AC | 892 ms
30,480 KB |
ソースコード
N,M=map(int,input().split()) A=list(map(int,input().split())) # UnionFind Group = [i for i in range(N+1)] # グループ分け Nodes = [1]*(N+1) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) for i in range(M): u,v=map(int,input().split()) Union(u,v) ANS=[0]*(N+1) for i in range(1,N+1): ANS[find(i)]+=A[i-1] score=1 for i in range(1,N+1): score=score*ANS[find(i)]%998244353 print(score)