結果

問題 No.2497 GCD of LCMs
ユーザー convexineqconvexineq
提出日時 2024-01-15 03:37:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 76,424 KB
最終ジャッジ日時 2024-01-15 03:37:53
合計ジャッジ時間 2,783 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
55,732 KB
testcase_01 AC 36 ms
55,732 KB
testcase_02 AC 37 ms
55,732 KB
testcase_03 AC 42 ms
55,732 KB
testcase_04 AC 36 ms
55,732 KB
testcase_05 AC 36 ms
55,732 KB
testcase_06 AC 37 ms
55,732 KB
testcase_07 AC 51 ms
64,120 KB
testcase_08 AC 58 ms
72,944 KB
testcase_09 AC 59 ms
72,944 KB
testcase_10 AC 56 ms
70,896 KB
testcase_11 AC 55 ms
68,848 KB
testcase_12 AC 62 ms
73,840 KB
testcase_13 AC 70 ms
76,424 KB
testcase_14 AC 48 ms
64,156 KB
testcase_15 AC 40 ms
55,732 KB
testcase_16 AC 62 ms
74,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
from math import gcd
lcm = lambda a,b: a//gcd(a,b)*b
import sys
readline = sys.stdin.readline

n,m = map(int,readline().split())
*a, = map(int,readline().split())

g = [[] for _ in range(n)]
for _ in range(m):
    u,v = map(int,readline().split())
    g[u-1].append(v-1)
    g[v-1].append(u-1)

inq = [0]*n
inq[0] = 1
dist = [0]*n
dist[0] = a[0]
q = deque([0])

while q:
    v = q.popleft()
    inq[v] = 0
    for w in g[v]:
        nc = gcd(lcm(dist[v],a[w]),dist[w])
        if nc == dist[w]: continue
        dist[w] = gcd(nc,dist[w])
        if inq[w] == 0:
            inq[w] = 1
            q.append(w)

for i in dist:print(i%998244353)
0