結果

問題 No.2497 GCD of LCMs
ユーザー convexineqconvexineq
提出日時 2024-01-13 17:46:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 767 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 76,636 KB
最終ジャッジ日時 2024-01-13 17:46:34
合計ジャッジ時間 2,926 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,588 KB
testcase_01 AC 37 ms
53,588 KB
testcase_02 AC 37 ms
53,588 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 36 ms
53,588 KB
testcase_06 AC 36 ms
53,588 KB
testcase_07 WA -
testcase_08 AC 55 ms
68,692 KB
testcase_09 AC 56 ms
68,692 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 40 ms
55,748 KB
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

#n,L,R = map(int,readline().split())
#*a, = map(int,readline().split())
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())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)

from math import gcd
def lcm(a,b):
    return a//gcd(a,b)*b

from heapq import *
q = [(a[0],0)]
dist = [-1]*n
dist[0] = a[0]

while q:
    c,v = q.pop()
    if dist[v] != -1 and c > dist[v]: continue
    for w in g[v]:
        gg = gcd(c,a[w])
        if gg == a[w]: continue
        nc = a[w]//gg*c
        if dist[w] == -1 or nc < dist[w]:
            dist[w] = nc
            heappush(q,(nc,w))

for i in dist:
    print(i%998244353)

0