#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
vector<int> g[MAXN];
vector<int> v[2];
int p[MAXN], sz[MAXN], ds[2];
bool flag[MAXN], dp[MAXN], notleaf[MAXN];
int RevDFS(int u, int b) {
  flag[u] = true;
  while (p[u] != 1) {
    flag[p[u]] = true;
    for (auto &x : g[p[u]])
      if (x != u) v[b].push_back(sz[x]);
    u = p[u];
  }
  return sz[u];
}
bool Check() {
  if (sz[1] % 2 == 1) return false;
  for (int k = 0; k < 2; ++k) {
    int m = (sz[1] - 2) / 2 - ds[k];
    memset(dp, 0, sizeof(dp));
    dp[0] = true;
    for (auto &x : v[k])
      for (int i = m - x; i >= 0; --i) dp[i + x] |= dp[i];
    if (!dp[m]) return false;
  }
  return true;
}
int main() {
  int n;
  int a, b, c, d;
  scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  for (int i = 2; i <= n; ++i)
    scanf("%d", &p[i]), g[p[i]].push_back(i), notleaf[p[i]] = true;
  for (int i = 1; i <= n; ++i)
    if (!notleaf[i]) sz[i] = 1;
  for (int i = n; i >= 1; --i) sz[p[i]] += sz[i];
  RevDFS(a, 0);
  ds[1] = RevDFS(b, 0);
  ds[0] = RevDFS(c, 1);
  RevDFS(d, 1);
  for (auto &x : g[1])
    if (!flag[x]) v[0].push_back(sz[x]), v[1].push_back(sz[x]);
  printf("%s\n", Check() ? "YES" : "NO");
  return 0;
}
