#include <bits/stdc++.h>
using namespace std;
long long t, n, m, u, v, q, k;
const int N = 5e3 + 50;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;
long long arr[N];
string str, ss;
int a, b, c, d;
int parent[N];
bool isleaf[N];
int sz[N];
vector<int> adj[N];
int V[4];
bitset<N> knapsack;
bool solve(int a, int b, int idx) {
  vector<int> elems;
  knapsack.reset();
  int find = sz[1] / 2 - 1;
  while (parent[a] != 1) {
    int fa = a;
    a = parent[a];
    for (int u : adj[a]) {
      if (u == fa) continue;
      elems.push_back(sz[u]);
    }
  }
  while (parent[b] != 1) {
    int fb = b;
    b = parent[b];
    for (int u : adj[b]) {
      if (u == fb) continue;
      elems.push_back(sz[u]);
    }
  }
  find -= sz[V[idx]];
  if (find < 0) return false;
  knapsack.set(0);
  for (int u : adj[1]) {
    bool valid = true;
    for (int k = 0; k < 4; ++k)
      if (V[k] == u) valid = false;
    if (valid) elems.push_back(sz[u]);
  }
  for (int k : elems) {
    knapsack |= (knapsack << k);
  }
  return knapsack.test(find);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  cin >> a >> b >> c >> d;
  for (int i = 2; i <= n; ++i) isleaf[i] = true;
  for (int i = 2; i <= n; ++i) {
    cin >> parent[i];
    isleaf[parent[i]] = false;
    adj[parent[i]].push_back(i);
  }
  V[0] = a;
  V[1] = b;
  V[2] = c;
  V[3] = d;
  for (int i = n; i >= 1; --i) {
    if (isleaf[i]) {
      sz[i] = 1;
    }
    sz[parent[i]] += sz[i];
  }
  for (int i = 0; i < 4; ++i) {
    while (parent[V[i]] != 1) {
      V[i] = parent[V[i]];
    }
  }
  if (sz[1] % 2 == 0 && solve(a, b, 2) && solve(c, d, 1)) {
    cout << "YES";
  } else
    cout << "NO";
  cout << endl;
  return 0;
}
