結果
問題 | No.2497 GCD of LCMs |
ユーザー |
![]() |
提出日時 | 2024-01-13 17:57:10 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 156 ms / 2,000 ms |
コード長 | 770 bytes |
コンパイル時間 | 339 ms |
コンパイル使用メモリ | 81,852 KB |
実行使用メモリ | 77,244 KB |
最終ジャッジ日時 | 2024-09-28 01:39:02 |
合計ジャッジ時間 | 2,659 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
import sysreadline = 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 -= 1v -= 1g[u].append(v)g[v].append(u)from math import gcddef lcm(a,b):return a//gcd(a,b)*bfrom heapq import *q = [(a[0],0)]dist = [0]*ndist[0] = a[0]while q:c,v = q.pop()if dist[v] != 0 and c > dist[v]: continuefor w in g[v]:nc = lcm(c,a[w])gg = gcd(nc,dist[w])if dist[w] != 0 and gg == dist[w]:continuedist[w] = gcd(nc,dist[w])heappush(q,(dist[w],w))for i in dist:print(i%998244353)