#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int size(const T& t) {
  return t.size();
}
int N;
int par[10000];
vector<int> son[10000];
int lisci = 0;
int rozm[100000];
int DFS(int A) {
  if (son[A].empty())
    rozm[A] = 1;
  else {
    for (__typeof((son[A]).begin()) it = ((son[A]).begin());
         it != (son[A]).end(); ++it)
      rozm[A] += DFS(*it);
  }
  return rozm[A];
}
bool jest[100000];
int mm;
void rob(int prz) {
  for (int a = (mm); a >= (0); --a)
    if (jest[a]) jest[a + prz] = 1;
  mm += prz;
}
int rodzice(int A) {
  while (par[A] != 0) {
    int p = par[A];
    for (__typeof((son[p]).begin()) it = ((son[p]).begin());
         it != (son[p]).end(); ++it)
      if (*it != A) rob(rozm[*it]);
    A = p;
  }
  return A;
}
void licz(int A, int B) {
  for (int a = 0; a < (lisci + 10); ++a) jest[a] = 0;
  mm = 0;
  jest[0] = 1;
  A = rodzice(A);
  B = rodzice(B);
  for (__typeof((son[0]).begin()) it = ((son[0]).begin()); it != (son[0]).end();
       ++it)
    if (*it != A && *it != B) rob(rozm[*it]);
  if (lisci % 2 || !jest[(lisci - 2) / 2]) {
    printf("NO\n");
    exit(0);
  }
}
int main() {
  int A, B, C, D;
  scanf("%d%d%d%d%d", &N, &A, &B, &C, &D);
  for (int a = (1); a <= (N - 1); ++a) {
    int p;
    scanf("%d", &p);
    --p;
    par[a] = p;
    son[p].push_back(a);
  }
  for (int a = 0; a < (N); ++a)
    if (son[a].empty()) ++lisci;
  DFS(0);
  licz(A, B);
  licz(C, D);
  printf("YES\n");
}
