#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 10;
const int N = 5e3 + 10;
vector<int> g[N];
int p[N];
int sz[N];
int special[N];
int dfs(int v) {
  sz[v] = g[v].empty();
  for (int &to : g[v]) {
    sz[v] += dfs(to);
  }
  return sz[v];
}
bool check(const vector<int> &a, const vector<int> &b, const int need) {
  bitset<N> d;
  d[0] = 1;
  for (const int &v : a) {
    d |= d << v;
  }
  for (const int &v : b) {
    d |= d << v;
  }
  return d[need];
}
int n;
int vV[4];
vector<int> szV[2];
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < 4; ++i) {
    scanf("%d", vV + i);
  }
  p[1] = 1;
  for (int x, i = 2; i <= n; ++i) {
    scanf("%d", &x);
    g[x].push_back(i);
    p[i] = x;
  }
  dfs(1);
  for (int i = 0; i < 4; ++i) {
    int v = vV[i];
    while (v != 1) {
      for (int &to : g[v]) {
        if (!special[to]) szV[i / 2].push_back(sz[to]);
      }
      special[v] = vV[i];
      v = p[v];
    }
  }
  vector<int> c;
  for (int to : g[1]) {
    if (special[to] == vV[2])
      szV[0].push_back(sz[to]);
    else if (special[to] == vV[1])
      szV[1].push_back(sz[to]);
    else
      c.push_back(sz[to]);
  }
  int k = sz[1];
  if (!(k & 1) && check(szV[0], c, k / 2 - 1) && check(szV[1], c, k / 2 - 1))
    puts("YES");
  else
    puts("NO");
}
int main() {
  solve();
  return 0;
}
