結果
| 問題 |
No.3283 Labyrinth and Friends
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-20 11:38:25 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 144 ms / 2,000 ms |
| コード長 | 738 bytes |
| コンパイル時間 | 280 ms |
| コンパイル使用メモリ | 82,168 KB |
| 実行使用メモリ | 78,472 KB |
| 最終ジャッジ日時 | 2025-09-25 21:03:22 |
| 合計ジャッジ時間 | 4,773 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 45 |
ソースコード
def merge(x,y):
ret=[1<<60]*(len(x)+len(y)-1)
for i in range(len(x)):
for j in range(len(y)):
ret[i+j]=min(ret[i+j],x[i]+y[j])
return ret
N,X=map(int,input().split())
p=list(map(int,input().split()))
res=[(0,0)]+[tuple(map(int,input().split())) for i in range(N-1)]
tree=[[] for i in range(N)]
for i in range(N-1):
tree[p[i]-1].append(i+1)
dp=[[0] for i in range(N)]
for i in reversed(range(N)):
for j in tree[i]:
dp[i]=merge(dp[i],dp[j])
ndp=[1<<60]*(res[i][1]+len(dp[i]))
ndp[0]=0
for j in reversed(range(len(dp[i]))):
ndp[j+res[i][1]]=min(ndp[j+res[i][1]],dp[i][j]+res[i][0])
dp[i]=ndp
ans=1<<60
for i in range(X,len(dp[0])):
ans=min(ans,dp[0][i])
print(ans)