結果
| 問題 |
No.30 たこやき工場
|
| コンテスト | |
| ユーザー |
ayaoni
|
| 提出日時 | 2020-12-04 16:46:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 60 ms / 5,000 ms |
| コード長 | 1,060 bytes |
| コンパイル時間 | 224 ms |
| コンパイル使用メモリ | 82,420 KB |
| 実行使用メモリ | 64,288 KB |
| 最終ジャッジ日時 | 2024-12-21 05:31:53 |
| 合計ジャッジ時間 | 2,026 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())
N,M = I(),I()
Graph = [[] for _ in range(N+1)]
flag = [1]*(N+1)
for _ in range(M):
P,Q,R = MI()
Graph[P].append((R,Q))
flag[R] = 0
def f(i):
if ANS[i] != -1:
return ANS[i]
if i == N:
ANS[N] = 1
return 1
res = 0
for j,c in Graph[i]:
if ANS[j] != -1:
res += ANS[j]*c
else:
x = f(j)
ANS[j] = x
res += x*c
ANS[i] = res
return res
ANS = [-1]*(N+1)
for i in range(1,N+1):
if ANS[i] == -1:
f(i)
ANS = [ANS[i] if flag[i] == 1 else 0 for i in range(1,N)]
print(*ANS,sep='\n')
ayaoni