#include <bits/stdc++.h>
using namespace std;
const int N = 5010, mod = int(1e9) + 7;
int n, a, b, c, d;
int dp[N], tin[N], tout[N], t;
vector<int> g[N], res;
bool used[N];
bitset<N> bp;
void dfs(int v) {
  used[v] = 1;
  tin[v] = ++t;
  dp[v] = 0;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (used[to]) continue;
    dfs(to);
    dp[v] += dp[to];
  }
  if (!dp[v]) dp[v] = 1;
  tout[v] = ++t;
}
bool ok(int u, int v) { return (tin[u] <= tin[v] && tout[u] >= tout[v]); }
void go(int v, int a, int pr = -1) {
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == pr) continue;
    if (ok(to, a)) {
      go(to, a, v);
    } else
      res.push_back(dp[to]);
  }
}
bool check(int a, int b, int c, int d) {
  res.clear();
  bp.reset();
  for (int i = 0; i < g[1].size(); i++) {
    int to = g[1][i];
    if (ok(to, d)) continue;
    if (ok(to, a)) {
      go(to, a, 1);
    } else if (ok(to, b)) {
      go(to, b, 1);
    } else if (ok(to, c)) {
      bp[dp[to]] = 1;
    } else {
      res.push_back(dp[to]);
    }
  }
  for (int i = 0; i < res.size(); i++) {
    int w = res[i];
    bp = (bp | (bp << w));
  }
  return bp[dp[1] / 2 - 1];
}
int main() {
  scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  for (int i = 2, x; i <= n; i++) {
    scanf("%d", &x);
    g[i].push_back(x);
    g[x].push_back(i);
  }
  dfs(1);
  if (dp[1] % 2 == 0 && check(a, b, c, d) && check(c, d, b, a)) {
    puts("YES");
  } else {
    puts("NO");
  }
  return 0;
}
