結果
| 問題 |
No.3283 Labyrinth and Friends
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-27 09:51:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 17 ms / 2,000 ms |
| コード長 | 952 bytes |
| コンパイル時間 | 2,503 ms |
| コンパイル使用メモリ | 201,252 KB |
| 実行使用メモリ | 34,472 KB |
| 最終ジャッジ日時 | 2025-09-27 09:51:15 |
| 合計ジャッジ時間 | 4,497 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, X;
cin >> N >> X;
vector<int> p(N);
for(int v = 1; v < N; v++) cin >> p[v], p[v]--;
vector<pair<int,int>> a(N);
for(int v = 1; v < N; v++){
auto &&[c, s] = a[v];
cin >> c >> s;
}
vector dp(N, array<ll,2001>());
for(int v = 0; v < N; v++){
dp[v].fill(1ll << 60);
dp[v][0] = 0;
}
vector<int> sz(N, 1);
for(int v = N - 1; v >= 1; v--){
auto [c, s] = a[v];
for(int i = sz[p[v]] - 1; i >= 0; i--){
for(int j = sz[v] - 1; j >= 0; j--){
dp[p[v]][i + j + s] = min(dp[p[v]][i + j + s], dp[p[v]][i] + dp[v][j] + c);
}
}
sz[p[v]] += sz[v] + s - 1;
}
ll ans = 1ll << 60;
for(int i = X; i < dp[0].size(); i++) ans = min(ans, dp[0][i]);
cout << ans << '\n';
}