#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const int MN = 5e3 + 10;
short mk[MN];
vector<int> Base, child[MN];
int n, sz[MN], par[MN], Sz[4];
int a, b, c, d;
void fail() {
  cout << "NO\n";
  exit(0);
}
void prep(int cur, short me, int f) {
  while (cur) {
    mk[cur] = me;
    if (par[cur] == 0) {
      Sz[f] = sz[cur];
    }
    cur = par[cur];
  }
}
bitset<MN> knap;
bool check(vector<int>& vec, int val) {
  if (val < 0) return false;
  knap = 0;
  knap[0] = 1;
  for (auto x : vec) knap |= (knap << x);
  return knap[val];
}
void solve() {
  int L = 0;
  for (int i = n - 1; ~i; --i) {
    if (child[i].empty()) sz[i] = 1, ++L;
    for (auto x : child[i]) sz[i] += sz[x];
  }
  if (L & 1) fail();
  prep(a, 1, 0), prep(b, 1, 1), prep(c, 2, 2), prep(d, 2, 3);
  for (auto v : child[0])
    if (!mk[v]) Base.push_back(sz[v]);
  vector<int> My;
  My = Base;
  for (int i = 1; i < n; ++i)
    if (mk[i] == 1) {
      for (auto v : child[i])
        if (!mk[v]) My.push_back(sz[v]);
    }
  if (!check(My, L / 2 - 1 - Sz[2])) fail();
  My = Base;
  for (int i = 1; i < n; ++i)
    if (mk[i] == 2) {
      for (auto v : child[i])
        if (!mk[v]) My.push_back(sz[v]);
    }
  if (!check(My, L / 2 - 1 - Sz[1])) fail();
  cout << "YES\n";
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  cin >> a >> b >> c >> d;
  --a, --b, --c, --d;
  for (int i = 1; i < n; ++i) {
    cin >> par[i], --par[i];
    child[par[i]].push_back(i);
  }
  solve();
  return 0;
}
