結果
問題 | No.2494 Sum within Components |
ユーザー |
![]() |
提出日時 | 2023-10-06 22:43:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 392 ms / 2,000 ms |
コード長 | 838 bytes |
コンパイル時間 | 510 ms |
コンパイル使用メモリ | 82,252 KB |
実行使用メモリ | 160,432 KB |
最終ジャッジ日時 | 2024-07-26 16:45:12 |
合計ジャッジ時間 | 3,813 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
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]*Nblock=[0]*Nsize=[1]*Ndef find(x):if par[x]==x:return xelse: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:returnif rank[x]>rank[y]:par[y]=xsize[x]+=size[y]else:par[x]=ysize[y]+=size[x]if rank[x]==rank[y]:rank[y]+=1for i in range(M):u,v=map(int, input().split())u-=1;v-=1C.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=998244353for d in D:c=0for a in D[d]:c+=A[a]for i in range(len(D[d])):ans*=cans%=modprint(ans)