#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 10;
int A, B, C, D;
int p[N];
vector<int> graph[N];
int q[N];
void dfs(int v) {
  if (!(int)(graph[v]).size()) q[v] = 1;
  for (auto to : graph[v]) {
    dfs(to);
    q[v] += q[to];
  }
}
bool mark[N];
int V[4];
vector<int> a[4];
vector<int> b;
const int M = N / 2;
int dp[2 * M];
int m;
bool possible(vector<int>& b, int u) {
  for (int i = 0; i < (int)(N); ++i) dp[i] = 0;
  dp[0] = 1;
  int crs = 0;
  for (int i = 0; i < (int)((int)(b).size()); ++i) {
    int in = i + 1;
    int val = b[i];
    for (int x = (int)(crs + 1) - 1; x >= 0; --x) {
      if (dp[x]) dp[x + val] = 1;
    }
    crs += b[i];
  }
  return u >= 0 && dp[u];
}
bool possible() {
  int S = 0;
  vector<int> v1 = b;
  vector<int> v2 = b;
  int val1 = m - 1;
  int val2 = m - 1;
  for (int u = 0; u < (int)(4); ++u) {
    for (auto val : a[u]) {
      if (u % 2 == 0)
        v1.push_back(val);
      else
        v2.push_back(val);
      if (u == 1) {
        val1 -= val;
      }
      if (u == 3) val2 -= val;
    }
  }
  return possible(v1, val1) && possible(v2, val2);
}
int n;
void solve() {
  scanf("%d", &n);
  scanf("%d%d%d%d", &V[0], &V[2], &V[1], &V[3]);
  for (int i = 2; i <= n; ++i) {
    scanf("%d", &p[i]);
    graph[p[i]].push_back(i);
  }
  dfs(1);
  for (int u = 0; u < (int)(4); ++u) {
    int cr = V[u];
    while (cr != 1) {
      for (auto to : graph[cr]) {
        if (!mark[to]) {
          a[u].push_back(q[to]);
        }
      }
      mark[cr] = 1;
      cr = p[cr];
    }
  }
  for (auto to : graph[1]) {
    if (!mark[to]) {
      b.push_back(q[to]);
    }
  }
  m = q[1];
  if (m % 2 == 1) {
    puts("NO");
    return;
  }
  m = m / 2 - 1;
  if (!possible()) {
    puts("NO");
    return;
  }
  puts("YES");
}
void testgen() {
  FILE* f = fopen("input.txt", "w");
  srand(time(0));
  fclose(f);
}
int main(int argc, char* argv[]) {
  cout << fixed;
  cout.precision(12);
  solve();
  return 0;
}
