結果
| 問題 | No.3283 Labyrinth and Friends | 
| コンテスト | |
| ユーザー |  沙耶花 | 
| 提出日時 | 2025-09-26 21:46:06 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 17 ms / 2,000 ms | 
| コード長 | 966 bytes | 
| コンパイル時間 | 3,862 ms | 
| コンパイル使用メモリ | 253,516 KB | 
| 実行使用メモリ | 35,164 KB | 
| 最終ジャッジ日時 | 2025-09-26 21:46:12 | 
| 合計ジャッジ時間 | 5,549 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 45 | 
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000005
#define Inf64 1000000000000000001LL
vector<vector<int>> E;
int sum[2005];
long long c[2005],s[2005];
long long dp[2005][2005];
void dfs(int cv){
	sum[cv] = s[cv];
	rep(i,E[cv].size()){
		int to = E[cv][i];
		dfs(to);
	}
	rep(i,2005)dp[cv][i] = Inf64;
	dp[cv][s[cv]] = c[cv];
	rep(i,E[cv].size()){
		int to = E[cv][i];
		for(int j=sum[cv];j>=0;j--){
		rep(k,sum[to]+1){
			dp[cv][j+k] = min(dp[cv][j+k],dp[cv][j]+dp[to][k]);
		}
	}
		sum[cv] += sum[to];
	}
	dp[cv][0] = 0;
		
}
int main(){
	
	int n,x;
	cin>>n>>x;
	E.resize(n);
	rep(i,n-1){
		int p;
		cin>>p;
		E[p-1].push_back(i+1);
	}
	for(int i=1;i<n;i++){
		cin>>c[i]>>s[i];
	}
	dfs(0);
	long long ans = Inf64;
	rep(i,2005){
		if(i>=x)ans = min(ans,dp[0][i]);
	}
	cout<<ans<<endl;
	
	return 0;
}
            
            
            
        