結果

問題 No.3250 最小公倍数
ユーザー かみのさちほ
提出日時 2025-08-29 22:50:09
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 895 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 60,368 KB
最終ジャッジ日時 2025-08-29 22:50:46
合計ジャッジ時間 31,437 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 5 TLE * 13 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

MOD = 998244353

N = int(input())
a_list = list(map(int, input().split()))

graph = [[] for n in range(N + 1)]

for n in range(N - 1):
    u, v = map(int, input().split())
    graph[u].append(v)
    graph[v].append(u)

used = [False]*(N + 1)
res = [0]*(N + 1)


def dfs(now):
    a = a_list[now - 1]
    neibors = graph[now]
    used[now] = True
    if len(neibors) == 1:
        res[now] = a 
        # print(f"{now}:{res}")
        return a
    else:
        a_s = [a]
        for neibor in neibors:
            if used[neibor] is True:
                continue
            else:
                used[neibor] = True
                c = dfs(neibor)
                a_s.append(c)
        # print(f"{now}:{a_s}")
        r = math.lcm(*a_s) 
        res[now] = r % MOD
        # print(f"{now}:{res}")
        return r


dfs(1)

# print(res)
for n in range(1, N + 1):
    print(res[n])
0