結果

問題 No.30 たこやき工場
ユーザー takakintakakin
提出日時 2020-06-24 21:57:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 586 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 8,772 KB
最終ジャッジ日時 2023-08-23 05:23:22
合計ジャッジ時間 1,281 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,572 KB
testcase_01 AC 20 ms
8,420 KB
testcase_02 AC 19 ms
8,600 KB
testcase_03 AC 19 ms
8,616 KB
testcase_04 AC 19 ms
8,428 KB
testcase_05 AC 19 ms
8,500 KB
testcase_06 AC 19 ms
8,640 KB
testcase_07 AC 19 ms
8,512 KB
testcase_08 AC 19 ms
8,508 KB
testcase_09 AC 19 ms
8,536 KB
testcase_10 AC 22 ms
8,772 KB
testcase_11 AC 20 ms
8,636 KB
testcase_12 AC 18 ms
8,604 KB
testcase_13 AC 19 ms
8,572 KB
testcase_14 AC 20 ms
8,520 KB
testcase_15 AC 19 ms
8,676 KB
testcase_16 AC 20 ms
8,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
Ans=[0]*n
Ans[-1]=1
Deg=[0]*n
m=int(input())
edge=[[] for _ in range(n)]
for _ in range(m):
  p,q,r=map(int,input().split())
  edge[r-1].append((p-1,q))
  Deg[p-1]+=1
from collections import deque
TS=[v for v in range(n) if Deg[v]==0]
D=deque(TS)
Used=[0]*n
while D:
  v=D.popleft()
  for g,q in edge[v]:
    Deg[g]-=1
    if Deg[g]==0:
      D.append(g)
      TS.append(g)
for i in range(n):
  v=TS[i]
  if edge[v]:
    for g,q in edge[v]:
      Ans[g]+=q*Ans[v]
    Ans[v]=0
Ans=Ans[:n-1]
for a in Ans:
  print(a)
0