結果

問題 No.30 たこやき工場
ユーザー ytftytft
提出日時 2022-11-04 02:48:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 548 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 86,736 KB
実行使用メモリ 76,820 KB
最終ジャッジ日時 2023-09-25 08:56:03
合計ジャッジ時間 3,512 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,300 KB
testcase_01 AC 73 ms
71,344 KB
testcase_02 AC 74 ms
71,180 KB
testcase_03 AC 73 ms
71,112 KB
testcase_04 AC 70 ms
71,300 KB
testcase_05 AC 71 ms
71,112 KB
testcase_06 AC 73 ms
71,316 KB
testcase_07 AC 72 ms
71,308 KB
testcase_08 AC 72 ms
71,116 KB
testcase_09 AC 73 ms
70,964 KB
testcase_10 AC 86 ms
76,820 KB
testcase_11 AC 71 ms
71,300 KB
testcase_12 AC 72 ms
71,116 KB
testcase_13 AC 71 ms
71,304 KB
testcase_14 AC 72 ms
71,400 KB
testcase_15 AC 73 ms
71,108 KB
testcase_16 AC 73 ms
71,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda:sys.stdin.readline().rstrip()
N,M=[int(input()) for i in range(2)]
prev=[[] for i in range(N)]
nex=[0 for i in range(N)]
quant=[int(i==N-1) for i in range(N)]
for i in range(M):
	P,Q,R=map(int,input().split())
	prev[R-1].append([P-1,Q])
	nex[P-1]+=1
check=[]
for i in range(N):
	if nex[i]==0:
		check.append(i)
while check:
	temp=check.pop()
	if len(prev[temp]):
		for i in prev[temp]:
			quant[i[0]]+=quant[temp]*i[1]
			nex[i[0]]-=1
			if nex[i[0]]==0:
				check.append(i[0])
		quant[temp]=0
for i in quant[:-1]:
	print(i)
0