結果

問題 No.30 たこやき工場
ユーザー titiatitia
提出日時 2021-11-16 08:10:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 464 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 8,368 KB
最終ジャッジ日時 2023-08-22 04:59:00
合計ジャッジ時間 1,413 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,824 KB
testcase_01 AC 18 ms
7,732 KB
testcase_02 AC 17 ms
7,744 KB
testcase_03 AC 17 ms
7,932 KB
testcase_04 AC 17 ms
7,824 KB
testcase_05 AC 15 ms
7,784 KB
testcase_06 AC 16 ms
7,924 KB
testcase_07 AC 16 ms
7,792 KB
testcase_08 AC 17 ms
7,812 KB
testcase_09 AC 17 ms
7,892 KB
testcase_10 AC 20 ms
8,368 KB
testcase_11 AC 17 ms
7,936 KB
testcase_12 AC 16 ms
7,752 KB
testcase_13 AC 17 ms
7,820 KB
testcase_14 AC 19 ms
7,820 KB
testcase_15 AC 16 ms
7,756 KB
testcase_16 AC 17 ms
7,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
M=int(input())
E=[[] for i in range(N+1)]
OUT=[0]*(N+1)

for i in range(M):
    p,q,r=map(int,input().split())
    E[r].append((p,q))
    OUT[p]+=1

Q=[]
for i in range(N+1):
    if OUT[i]==0:
        Q.append(i)

ANS=[0]*(N+1)
ANS[-1]=1
while Q:
    x=Q.pop()
    for to,q in E[x]:
        OUT[to]-=1
        if OUT[to]==0:
            Q.append(to)
        ANS[to]+=ANS[x]*q

    if E[x]!=[]:
        ANS[x]=0

print("\n".join(map(str,ANS[1:-1])))
0