#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
bitset<N> knapsack(vector<int> v) {
  bitset<N> ret;
  ret[0] = 1;
  for (int a : v) ret |= ret << a;
  return ret;
}
int n, p[N], sz[N], mark[N];
vector<int> G[N];
void getsz(int u) {
  sz[u] = (G[u].size() == 0 ? 1 : 0);
  for (int v : G[u]) {
    getsz(v);
    sz[u] += sz[v];
  }
}
bool solve(int a, int b, int c) {
  memset(mark, 0, sizeof mark);
  mark[c] = true;
  while (p[c]) {
    c = p[c];
    mark[c] = true;
  }
  vector<int> have;
  mark[a] = true;
  for (int u = p[a]; u != -1; u = p[u])
    for (int v : G[u])
      if (!mark[v]) have.push_back(sz[v]), mark[v] = true;
  mark[b] = true;
  for (int u = p[b]; u != -1; u = p[u])
    for (int v : G[u])
      if (!mark[v]) have.push_back(sz[v]), mark[v] = true;
  if (sz[0] % 2 || sz[0] / 2 - 1 - sz[c] < 0)
    return false;
  else
    return (knapsack(have))[sz[0] / 2 - 1 - sz[c]];
}
int main() {
  int a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a--;
  b--;
  c--;
  d--;
  p[0] = -1;
  for (int i = 1; i < n; i++) {
    cin >> p[i];
    p[i]--;
    G[p[i]].push_back(i);
  }
  getsz(0);
  if (solve(a, b, c) && solve(c, d, b))
    cout << "YES\n";
  else
    cout << "NO\n";
}
