#include <bits/stdc++.h>
using namespace std;
int p[5010];
vector<int> ch[5010];
int siz[5010];
int n, N;
int f[5010], g[5010];
void ins(int* F, int x) {
  for (int i = N; i >= x; i--) F[i] = F[i] | F[i - x];
  return;
}
bool vis[5010];
void work(int& u, int* F) {
  vis[u] = true;
  while (p[u] != 1) {
    u = p[u];
    vis[u] = true;
    for (int i = 0; i < ch[u].size(); i++)
      if (!vis[ch[u][i]]) ins(F, siz[ch[u][i]]);
  }
  return;
}
int main() {
  scanf("%d", &n);
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &p[i]);
    ch[p[i]].push_back(i);
    siz[i] = 1;
    siz[p[i]] = 0;
  }
  for (int i = n; i >= 2; i--) siz[p[i]] += siz[i];
  N = siz[1];
  if (N & 1) {
    printf("NO\n");
    return 0;
  }
  N = N / 2 - 1;
  f[0] = g[0] = 1;
  work(a, f);
  work(b, f);
  work(c, g);
  work(d, g);
  for (int i = 0; i < ch[1].size(); i++) {
    int v = ch[1][i];
    if (vis[v]) continue;
    ins(f, siz[v]);
    ins(g, siz[v]);
  }
  if (siz[c] <= N && siz[b] <= N && f[N - siz[c]] && g[N - siz[b]])
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
