結果
| 問題 |
No.3283 Labyrinth and Friends
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-26 21:51:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 1,607 bytes |
| コンパイル時間 | 3,638 ms |
| コンパイル使用メモリ | 255,624 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-09-26 21:51:35 |
| 合計ジャッジ時間 | 5,245 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using isize = size_t;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
using f64 = long double;
using p2 = pair<i64, i64>;
using el = tuple<i64, i64, i64>;
using mint = atcoder::modint998244353;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(18);
_main();
}
i64 pow(i64 x, i64 n) {
i64 res = 1;
i64 t = x;
while (n > 0) {
if (n & 1) res *= t;
t *= t;
n >>= 1;
}
return res;
}
i64 pow(i64 x, i64 n, i64 m) {
i64 res = 1;
i64 t = x % m;
while (n > 0) {
if (n & 1) res = res * t % m;
t = t * t % m;
n >>= 1;
}
return res;
}
i64 n, x;
vector<i64> dp[2000];
vector<i64> g[2000];
i64 s[2000], c[2000];
void dfs(i64 v) {
dp[v] = vector<i64>(s[v] + 1, 1e18);
dp[v][s[v]] = c[v];
for (i64 nv : g[v]) {
dfs(nv);
vector<i64> ndp(dp[v].size() + dp[nv].size() - 1, 1e18);
for (i64 i = 0; i < dp[v].size(); i++) {
ndp[i] = min(ndp[i], dp[v][i]);
for (i64 j = 0; j < dp[nv].size(); j++) {
ndp[i + j] = min(ndp[i + j], dp[v][i] + dp[nv][j]);
}
}
swap(ndp, dp[v]);
}
}
void _main() {
cin >> n >> x;
for (i64 i = 1; i < n; i++) {
i64 p;
cin >> p;
p--;
g[p].push_back(i);
}
s[0] = c[0] = 0;
for (i64 i = 1; i < n; i++) {
cin >> c[i] >> s[i];
}
dfs(0);
i64 ans = 1e18;
for (i64 i = x; i < dp[0].size(); i++) ans = min(ans, dp[0][i]);
cout << ans << "\n";
}