Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-8;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; i++)
#define per(i, f, t) for (auto i = f; i >= t; i--)

ll power(ll x, ll y, ll mod) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

inline void add(ll &x, ll y, ll mod) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

inline ll sum(ll x, ll y, ll mod) {
    add(x, y, mod);
    return x;
}

template<typename A, typename B> inline bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> inline bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> inline void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> inline void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(15);
    run();
    return 0;
}

// == SOLUTION == //

const int N = 10005;

int n;
vector<int> g[N];
int x[N], dp[N];
int cur[N], nxt[N];

void dfs(int v) {
    fill(cur, cur + N, INF);
    cur[0] = 0;
    for (int u : g[v]) {
        dfs(u);
        fill(nxt, nxt + N, INF);
        rep(i, 0, K) {
            if (i + x[u] < N) {
                mini(nxt[i + x[u]], cur[i] + dp[u]);
            }
            if (i + dp[u] < N) {
                mini(nxt[i + dp[u]], cur[i] + x[u]);
            }
        }
        copy(nxt, nxt + N, cur);
    }
    
    dp[v] = INF;
    rep(i, 0, x[v] + 1) {
        mini(dp[v], cur[i]);
    }
    
    if (dp[v] == INF) {
        cout << "IMPOSSIBLE\n";
        exit(0);
    }
}

void run() {
    cin >> n;
    rep(i, 2, n + 1) {
        int p;
        cin >> p;
        g[p].pb(i);
    }
    rep(i, 1, n + 1) {
        cin >> x[i];
    }
    dfs(1);
    cout << "POSSIBLE\n";
}


Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:113:19: error: 'K' was not declared in this scope
  113 |         rep(i, 0, K) {
      |                   ^
a.cc:19:43: note: in definition of macro 'rep'
   19 | #define rep(i, f, t) for (auto i = f; i < t; i++)
      |                                           ^