結果
| 問題 |
No.3250 最小公倍数
|
| コンテスト | |
| ユーザー |
かみのさちほ
|
| 提出日時 | 2025-08-29 22:37:33 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,015 bytes |
| コンパイル時間 | 830 ms |
| コンパイル使用メモリ | 12,160 KB |
| 実行使用メモリ | 64,116 KB |
| 最終ジャッジ日時 | 2025-10-16 16:26:32 |
| 合計ジャッジ時間 | 5,932 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 WA * 1 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):
# print(f"now:{now}")
a = a_list[now - 1]
a_s = [a]
neibors = graph[now]
used[now] = True
if len(neibors) == 1:
res[now] = a
# print(f"{now}:{a_s}")
# print(f"{now}:{res}")
return a_s
else:
# print(a_s)
for neibor in neibors:
if used[neibor] is True:
continue
else:
used[neibor] = True
c = dfs(neibor)
# print(f"{now}:{neibor}={c}")
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])
かみのさちほ