結果
問題 |
No.3250 最小公倍数
|
ユーザー |
![]() |
提出日時 | 2025-08-29 22:28:43 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 868 bytes |
コンパイル時間 | 286 ms |
コンパイル使用メモリ | 12,288 KB |
実行使用メモリ | 63,972 KB |
最終ジャッジ日時 | 2025-08-29 22:28:48 |
合計ジャッジ時間 | 4,994 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | WA * 4 TLE * 1 -- * 16 |
ソースコード
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] a_s = [a] neibors = graph[now] if len(neibors) == 1: res[now] = a # print(f"{now}:{res}") return a_s else: for neibor in neibors: if used[neibor] is True: continue else: used[neibor] = True c = dfs(neibor) a_s += c # print(f"{now}:{a_s}") r = math.lcm(*a_s) % MOD res[now] = r # print(f"{now}:{res}") return a_s dfs(1) # print(res) for n in range(1, N + 1): print(res[n])