#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 5000;
typedef struct Knap {
  int opt[MAXN], nopt;
  bool dp[MAXN + 1];
  void clear() { nopt = 0; }
  void add(int x) { opt[nopt++] = x; }
  bool can(int want) {
    for (int j = (0); j <= (want); ++j) dp[j] = false;
    dp[0] = true;
    for (int i = (0); i < (nopt); ++i)
      for (int j = want; j >= opt[i]; --j)
        if (dp[j - opt[i]]) dp[j] = true;
    return dp[want];
  }
} Knap;
Knap knap;
int n;
int A, B, C, D;
int par[MAXN];
int chead[MAXN], cnxt[MAXN];
int sz[MAXN];
int mask[MAXN];
void dfs(int at) {
  sz[at] = chead[at] == -1 ? 1 : 0;
  mask[at] = 0;
  if (at == A) mask[at] |= 1;
  if (at == B) mask[at] |= 2;
  if (at == C) mask[at] |= 4;
  if (at == D) mask[at] |= 8;
  for (int to = chead[at]; to != -1; to = cnxt[to]) {
    dfs(to);
    sz[at] += sz[to];
    mask[at] |= mask[to];
  }
}
void run() {
  scanf("%d", &n);
  scanf("%d%d%d%d", &A, &B, &C, &D);
  --A, --B, --C, --D;
  par[0] = -1;
  for (int i = (1); i < (n); ++i) {
    scanf("%d", &par[i]);
    --par[i];
  }
  for (int i = (0); i < (n); ++i) chead[i] = -1;
  for (int i = (1); i < (n); ++i) cnxt[i] = chead[par[i]], chead[par[i]] = i;
  dfs(0);
  int nleaf = 0;
  for (int i = (0); i < (n); ++i)
    if (chead[i] == -1) ++nleaf;
  if (nleaf % 2 == 1) {
    printf("NO\n");
    return;
  }
  for (int x = (0); x < (2); ++x) {
    knap.clear();
    int want = nleaf / 2 - 1;
    for (int i = (1); i < (n); ++i)
      if (par[i] == 0 && mask[i] == 0) knap.add(sz[i]);
    for (int i = (1); i < (n); ++i)
      if (mask[i] == 0 && (mask[par[i]] == (1 << (0 + 2 * x)) ||
                           mask[par[i]] == (1 << (1 + 2 * x))))
        knap.add(sz[i]);
    for (int i = (1); i < (n); ++i)
      if (par[i] == 0 && mask[i] == (1 << (2 - x))) want -= sz[i];
    if (!knap.can(want)) {
      printf("NO\n");
      return;
    }
  }
  printf("YES\n");
}
int main() {
  run();
  return 0;
}
