結果

問題 No.2494 Sum within Components
ユーザー sasa8uyauyasasa8uyauya
提出日時 2023-10-06 21:52:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 356 ms / 2,000 ms
コード長 529 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 103,780 KB
最終ジャッジ日時 2023-10-06 21:52:38
合計ジャッジ時間 4,557 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,528 KB
testcase_01 AC 67 ms
71,356 KB
testcase_02 AC 68 ms
71,384 KB
testcase_03 AC 69 ms
71,448 KB
testcase_04 AC 66 ms
71,212 KB
testcase_05 AC 68 ms
71,416 KB
testcase_06 AC 66 ms
71,532 KB
testcase_07 AC 68 ms
71,292 KB
testcase_08 AC 69 ms
71,464 KB
testcase_09 AC 143 ms
79,156 KB
testcase_10 AC 155 ms
80,200 KB
testcase_11 AC 127 ms
79,280 KB
testcase_12 AC 162 ms
79,576 KB
testcase_13 AC 155 ms
79,640 KB
testcase_14 AC 317 ms
99,008 KB
testcase_15 AC 339 ms
91,780 KB
testcase_16 AC 219 ms
96,612 KB
testcase_17 AC 170 ms
103,780 KB
testcase_18 AC 225 ms
103,008 KB
testcase_19 AC 356 ms
103,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def union(x,y):
  rx=root(x)
  ry=root(y)
  if rx==ry:
    return
  if rx>ry:
    rx,ry=ry,rx
  r[ry]=rx
  return

def root(x):
  p=x
  l=[p]
  while r[p]!=p:
    p=r[p]
    l.append(p)
  for p in l:
    r[p]=l[-1]
  return r[x]

M=998244353
n,m=map(int,input().split())
a=list(map(int,input().split()))
r=list(range(n))

for i in range(m):
  u,v=map(int,input().split())
  u-=1
  v-=1
  union(u,v)

g=[0]*n
for i in range(n):
  ri=root(i)
  g[ri]+=a[i]
  g[ri]%=M

b=1
for i in range(n):
  ri=root(i)
  b*=g[ri]
  b%=M

print(b)
0