結果

問題 No.2494 Sum within Components
ユーザー CecilCecil
提出日時 2023-10-06 23:16:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 678 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 14,900 KB
最終ジャッジ日時 2023-10-06 23:16:06
合計ジャッジ時間 4,545 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
13,056 KB
testcase_01 AC 19 ms
8,580 KB
testcase_02 AC 20 ms
8,576 KB
testcase_03 AC 20 ms
8,580 KB
testcase_04 AC 19 ms
8,544 KB
testcase_05 AC 18 ms
8,544 KB
testcase_06 AC 18 ms
8,496 KB
testcase_07 AC 19 ms
8,644 KB
testcase_08 AC 19 ms
8,584 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N,M = map(int, input().split())
A =list(map(int, input().split()))
G = [ [] for _ in range(N+1) ]
for _ in range(M):
    u,m = map(int, input().split())
    G[u].append(m)
    G[m].append(u)

def bfs(start):
    dist = [False]*(N+1)
    dist[start] = True
    que = deque()
    que.append(start)
    cnt = A[start-1]
    while que:
        v = que.popleft()
        for v2 in G[v]:
            if dist[v2] != False:
                continue
            dist[v2] = True
            cnt += A[v2-1]
            que.append(v2)
    return cnt
ans = 1
for i in range(1, N+1):
    num= bfs(i)
    #print(num)
    ans *= num
    ans %= 998244353
print(ans)
0