結果

問題 No.623 fudan no modulus to tigau
ユーザー wajima_wataru
提出日時 2017-12-29 20:54:57
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 369 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-12-21 10:35:21
合計ジャッジ時間 1,237 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
TAB = [tuple(map(int, input().split())) for _ in range(N - 1)]
Q = int(input())
for x in list(map(int, input().split())):
	f = [1, x]
	for i in range(N - 1):
		t, a, b = TAB[i]
		if t == 1:
			f.append((f[a] + f[b]) % 998244353)
		elif t == 2:
			f.append((a * f[b]) % 998244353)
		else:
			f.append((f[a] * f[b]) % 998244353)
	print(f[N] % 998244353)
0