#include <bits/stdc++.h>
using namespace std;
int n, sz[5001], sp[5001], of[5001], L;
bitset<5001> dp;
vector<int> tr[5001];
void pl(int v = 1, int p = 0) {
  if (of[v]) sp[v] = 1 << of[v];
  if (v != 1 && (int)tr[v].size() == 1) {
    sz[v] = 1;
    return;
  }
  for (int i = 0; i < (int)(tr[v].size()); ++i) {
    int u = tr[v][i];
    if (u == p) continue;
    pl(u, v);
    sz[v] += sz[u];
    sp[v] |= sp[u];
  }
}
inline int bo(int x) {
  int an = -1;
  while (x) ++an, x >>= 1;
  return an;
}
void no() { printf("NO\n"), exit(0); }
int main() {
  scanf("%d", &n);
  for (int i = 1; i < (int)(5); ++i) {
    int x;
    scanf("%d", &x);
    of[x] = i;
  }
  for (int i = 2; i < (int)(n + 1); ++i) {
    int t;
    scanf("%d", &t);
    tr[i].push_back(t);
    tr[t].push_back(i);
  }
  pl();
  int fs[4];
  vector<int> x;
  for (int i = 0; i < (int)(tr[1].size()); ++i) {
    int u = tr[1][i];
    L += sz[u];
    if (sp[u])
      fs[bo(sp[u]) - 1] = sz[u];
    else
      x.push_back(sz[u]);
  }
  if (L & 1) no();
  dp[0] = true;
  dp[fs[2]] = true;
  for (int i = 0; i < (int)(x.size()); ++i)
    for (int j = L - x[i]; j >= 0; --j)
      if (dp[j]) dp[j + x[i]] = true;
  L = L - 2 >> 1;
  int s = max(0, L - (fs[0] + fs[1]) + 2);
  bool ok = false;
  for (int i = s; i < (int)(L + 1); ++i)
    if (dp[i]) {
      ok = true;
      break;
    }
  if (!ok) no();
  dp.reset();
  dp[0] = true;
  dp[fs[1]] = true;
  for (int i = 0; i < (int)(x.size()); ++i)
    for (int j = L - x[i]; j >= 0; --j)
      if (dp[j]) dp[j + x[i]] = true;
  s = max(0, L - (fs[2] + fs[3]) + 2);
  for (int i = s; i < (int)(L + 1); ++i)
    if (dp[i]) printf("YES\n"), exit(0);
  no();
}
