結果

問題 No.2494 Sum within Components
ユーザー 👑 timitimi
提出日時 2023-10-06 22:43:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 461 ms / 2,000 ms
コード長 838 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 160,452 KB
最終ジャッジ日時 2023-10-06 22:43:17
合計ジャッジ時間 5,086 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,444 KB
testcase_01 AC 74 ms
71,584 KB
testcase_02 AC 72 ms
71,668 KB
testcase_03 AC 70 ms
71,316 KB
testcase_04 AC 71 ms
71,308 KB
testcase_05 AC 73 ms
71,388 KB
testcase_06 AC 72 ms
71,616 KB
testcase_07 AC 76 ms
71,576 KB
testcase_08 AC 70 ms
71,348 KB
testcase_09 AC 141 ms
80,548 KB
testcase_10 AC 177 ms
81,452 KB
testcase_11 AC 129 ms
80,132 KB
testcase_12 AC 200 ms
81,420 KB
testcase_13 AC 195 ms
81,932 KB
testcase_14 AC 406 ms
105,024 KB
testcase_15 AC 355 ms
102,324 KB
testcase_16 AC 226 ms
101,868 KB
testcase_17 AC 200 ms
160,452 KB
testcase_18 AC 246 ms
142,460 KB
testcase_19 AC 461 ms
130,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int, input().split())
A=list(map(int, input().split()))
B=[0]*N;C=[]
par=[i for i in range(N)]
rank=[0]*(N)
friend=[0]*N
block=[0]*N
size=[1]*N
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
 
#同じ集合か判定
def same(x,y):
  return find(x)==find(y)
 
def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1
 
 
for i in range(M):
  u,v=map(int, input().split())
  u-=1;v-=1
  C.append((u,v))
  union(u,v)
  
D={}
for i in range(N):
  d=find(i)
  if d not in D:
    D[d]=[]
  D[d].append(i)

ans=1;mod=998244353
for d in D:
  c=0
  for a in D[d]:
    c+=A[a]
  for i in range(len(D[d])):
    ans*=c 
    ans%=mod 
print(ans)
  
  
0