#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <math.h>
#include <map>
#include <set>
#include <stdio.h>
#include <stack>
#include <unordered_map>
#define ll long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pib pair<int, bool>
#define pdd pair<double, double>
#define pss pair<string, string>
#pragma comment(linker, "/STACK:251777215")
using namespace std;

const ll maxn = 1001;
const ll maxm = 10001;
const ll maxk = 1001;
const ll maxq = 1000001;
const ll margin = 1001;
const ll maxseg = 262144;
const ll secret_number = -87468267;
const pii secret_pair = make_pair(secret_number, secret_number);
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const int iinf = 2147483647 / 2;
const double pi = 3.141592653589793238462643383279502884;
const double eps = 1e-7;
const string something_very_long = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
const string govno = "g";
string impossible = "-1";

void printout(string str)
{
	cout << str;
	exit(0);
}

void Impossible()
{
	printout(impossible);
}

void print(char x, int numb)
{
	for (int i = 0; i < numb; ++i)
		cout << x;
}

int n, m, L, S, T;
vector<ll> edges[maxn];
vector<ll> weights[maxn];
vector<ll> numbers[maxn];
ll distances[maxn];
ll distances2[maxn];

void say_yes()
{
	cout << "YES\n";
	map<pii, ll> weightes;
	for (int i = 0; i < maxn; ++i)
	{
		for (int j = 0; j < edges[i].size(); ++j)
		{
			if (weights[i][j] == 0)
			{
				weights[i][j] = 1e15;
				weights[edges[i][j]][numbers[i][j]] = 1e15;
			}
			if (i <= edges[i][j])
				weightes[pii(i, edges[i][j])] = weights[i][j];
			else
				weightes[pii(edges[i][j], i)] = weights[i][j];
		}
	}
	for (auto it = weightes.begin(); it != weightes.end(); it++)
	{
		cout << it->first.first << ' ' << it->first.second << ' ' << it->second << '\n';
	}
	exit(0);
}

void say_no()
{
	printout("NO");
}

int main()
{
	for (int i = 0; i < maxn; ++i)
		distances[i] = inf;
	for (int i = 0; i < maxn; ++i)
		distances2[i] = inf;
	cin >> n >> m >> L >> S >> T;
	for (int i = 0; i < m; ++i)
	{
		int x, y, w;
		cin >> x >> y >> w;
		edges[x].push_back(y);
		edges[y].push_back(x);
		weights[x].push_back(w);
		weights[y].push_back(w);
		numbers[x].push_back(edges[y].size() - 1);
		numbers[y].push_back(edges[x].size() - 1);
	}
	priority_queue<pair<ll, ll>> q;
	q.push(pll(0, S));
	distances[S] = 0;
	while (!q.empty())
	{
		pll cur_pair = q.top();
		q.pop();
		ll cur_elem = cur_pair.ss;
		if (distances[cur_elem] != -cur_pair.ff)
			continue;
		for (int i = 0; i < edges[cur_elem].size(); ++i)
		{
			ll next = edges[cur_elem][i];
			ll next_dist = weights[cur_elem][i];
			if (next_dist == 0)
				continue;
			if (distances[next] > distances[cur_elem] + next_dist)
			{
				distances[next] = distances[cur_elem] + next_dist;
				q.push(pll(-distances[next], next));
			}
		}
	}
	if (distances[T] == L)
		say_yes();
	if (distances[T] < L)
		say_no();
	q.push(pll(0, T));
	distances2[T] = 0;
	while (!q.empty())
	{
		pll cur_pair = q.top();
		q.pop();
		ll cur_elem = cur_pair.ss;
		if (distances2[cur_elem] != -cur_pair.ff)
			continue;
		for (int i = 0; i < edges[cur_elem].size(); ++i)
		{
			ll next = edges[cur_elem][i];
			ll next_dist = weights[cur_elem][i];
			if (next_dist == 0)
				continue;
			if (distances2[next] > distances2[cur_elem] + next_dist)
			{
				distances2[next] = distances2[cur_elem] + next_dist;
				q.push(pll(-distances2[next], next));
			}
		}
	}

	// here solution starts
	q.push(pll(0, S));
	bool f = false;
	while (!q.empty())
	{
		pll cur_pair = q.top();
		q.pop();
		ll cur_elem = cur_pair.ss;
		if (distances[cur_elem] != -cur_pair.ff)
			continue;
		for (int i = 0; i < edges[cur_elem].size(); ++i)
		{
			ll next = edges[cur_elem][i];
			ll next_dist = weights[cur_elem][i];
			if (next_dist == 0)
			{
				if (distances2[next] == inf)
				{
					distances[next] = distances[cur_elem] + 1;
					weights[cur_elem][i] = 1;
					weights[next][numbers[cur_elem][i]] = 1;
					q.push(pll(-distances[next], next));
				}
				else
				{
					weights[cur_elem][i] = max((ll)1, L - distances[cur_elem] - distances2[next]);
					weights[next][numbers[cur_elem][i]] = max((ll)1, L - distances[cur_elem] - distances2[next]);
					if (L - distances[cur_elem] - distances2[next] >= 1)
					{
						f = true;
						break;
					}
					distances[next] = distances[cur_elem] + weights[cur_elem][i];
					q.push(pll(-distances[next], next));
				}
			}
			else if (distances[next] >= distances[cur_elem] + next_dist)
			{
				distances[next] = distances[cur_elem] + next_dist;
				q.push(pll(-distances[next], next));
			}
		}
		if (f)
			break;
	}

	for (int i = 0; i < maxn; ++i)
	{
		for (int j = 0; j < weights[i].size(); ++i)
		{
			if (weights[i][j] == 0)
			{
				weights[i][j] = 1e15;
				weights[edges[i][j]][numbers[i][j]] = 1e15;
			}
		}
	}

	// check
	for (int i = 0; i < maxn; ++i)
		distances[i] = inf;
	q.push(pll(0, S));
	distances[S] = 0;
	while (!q.empty())
	{
		pll cur_pair = q.top();
		q.pop();
		ll cur_elem = cur_pair.ss;
		if (distances[cur_elem] != -cur_pair.ff)
			continue;
		for (int i = 0; i < edges[cur_elem].size(); ++i)
		{
			ll next = edges[cur_elem][i];
			ll next_dist = weights[cur_elem][i];
			if (next_dist == 0)
				continue;
			if (distances[next] > distances[cur_elem] + next_dist)
			{
				distances[next] = distances[cur_elem] + next_dist;
				q.push(pll(-distances[next], next));
			}
		}
	}

	if (distances[T] == L)
		say_yes();
	else
		say_no();
	return 0;
}
/*
2 1 1000000000 1 0
0 1 999999999
*/


#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <math.h>
#include <map>
#include <set>
#include <stdio.h>
#include <stack>
#include <unordered_map>
#define ll long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pib pair<int, bool>
#define pdd pair<double, double>
#define pss pair<string, string>
#pragma comment(linker, "/STACK:251777215")
using namespace std;

const ll maxn = 1011;
const ll maxm = 10001;
const ll maxk = 1001;
const ll maxq = 1000001;
const ll margin = 1001;
const ll maxseg = 262144;
const ll secret_number = -87468267;
const pii secret_pair = make_pair(secret_number, secret_number);
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const int iinf = 2147483647 / 2;
const double pi = 3.141592653589793238462643383279502884;
const double eps = 1e-7;
const string something_very_long = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
const string govno = "g";
string impossible = "-1";

void printout(string str)
{
	cout << str;
	exit(0);
}

void Impossible()
{
	printout(impossible);
}

void print(char x, int numb)
{
	for (int i = 0; i < numb; ++i)
		cout << x;
}

int n, m, L, S, T;
vector<ll> edges[maxn];
vector<ll> weights[maxn];
vector<ll> numbers[maxn];
ll distances[maxn];
ll distances2[maxn];

void set_edge_len(int v, int numb, ll val)
{
	weights[v][numb] = val;
	weights[edges[v][numb]][numbers[v][numb]] = val;
}

void say_yes()
{
	cout << "YES\n";
	for (int i = 0; i < maxn; ++i)
		for (int j = 0; j < edges[i].size(); ++j)
			if (i < edges[i][j])
				cout << i << ' ' << edges[i][j] << ' ' << ((weights[i][j] == 0) ? 1e15 : weights[i][j]) << '\n';
	exit(0);
}

void say_no()
{
	printout("NO");
}

int main()
{
	for (int i = 0; i < maxn; ++i)
		distances[i] = inf;
	for (int i = 0; i < maxn; ++i)
		distances2[i] = inf;
	cin >> n >> m >> L >> S >> T;
	for (int i = 0; i < m; ++i)
	{
		int x, y, w;
		cin >> x >> y >> w;
		edges[x].push_back(y);
		edges[y].push_back(x);
		weights[x].push_back(w);
		weights[y].push_back(w);
		numbers[x].push_back(edges[y].size() - 1);
		numbers[y].push_back(edges[x].size() - 1);
	}
	priority_queue<pair<ll, ll>> q;
	q.push(pll(0, S));
	distances[S] = 0;
	while (!q.empty())
	{
		pll cur_pair = q.top();
		q.pop();
		ll cur_elem = cur_pair.ss;
		if (distances[cur_elem] != -cur_pair.ff)
			continue;
		for (int i = 0; i < edges[cur_elem].size(); ++i)
		{
			ll next = edges[cur_elem][i];
			ll next_dist = weights[cur_elem][i];
			if (next_dist == 0)
				continue;
			if (distances[next] > distances[cur_elem] + next_dist)
			{
				distances[next] = distances[cur_elem] + next_dist;
				q.push(pll(-distances[next], next));
			}
		}
	}
	if (distances[T] == L)
		say_yes();
	if (distances[T] < L)
		say_no();

	// here solution starts
	q.push(pll(0, T));
	distances2[T] = 0;
	bool f = false;
	while (!q.empty())
	{
		pll cur_pair = q.top();
		q.pop();
		ll cur_elem = cur_pair.ss;
		if (distances2[cur_elem] != -cur_pair.ff)
			continue;
		for (int i = 0; i < edges[cur_elem].size(); ++i)
		{
			ll next = edges[cur_elem][i];
			ll next_dist = weights[cur_elem][i];
			if (next_dist == 0)
			{
				if (distances[next] == inf)
				{
					weights[cur_elem][i] = 1;
					weights[next][numbers[cur_elem][i]] = 1;
					if (distances2[cur_elem] + 1 < distances2[next])
					{
						distances2[next] = distances2[cur_elem] + 1;
						q.push(pll(-distances2[next], next));
					}
				}
				else
				{
					weights[cur_elem][i] = max((ll)1, L - distances2[cur_elem] - distances[next]);
					weights[next][numbers[cur_elem][i]] = max((ll)1, L - distances2[cur_elem] - distances[next]);
					if (L - distances2[cur_elem] - distances[next] >= 1)
					{
						f = true;
						break;
					}
					if (distances2[cur_elem] + weights[cur_elem][i] < distances2[next])
					{
						distances2[next] = distances2[cur_elem] + weights[cur_elem][i];
						q.push(pll(-distances2[next], next));
					}
				}
			}
			else if (distances2[next] >= distances2[cur_elem] + next_dist)
			{
				distances2[next] = distances2[cur_elem] + next_dist;
				q.push(pll(-distances2[next], next));
			}
		}
		if (f)
			break;
	}

	if (f)
		say_yes();
	else
		say_no();
	return 0;
}
/*

*/


#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <math.h>
#include <map>
#include <set>
#include <stdio.h>
#include <stack>
#include <unordered_map>
#define ll long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pib pair<int, bool>
#define pdd pair<double, double>
#define pss pair<string, string>
#pragma comment(linker, "/STACK:251777215")
using namespace std;

const ll maxn = 1011;
const ll maxm = 10001;
const ll maxk = 1001;
const ll maxq = 1000001;
const ll margin = 1001;
const ll maxseg = 262144;
const ll secret_number = -87468267;
const pii secret_pair = make_pair(secret_number, secret_number);
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const int iinf = 2147483647 / 2;
const double pi = 3.141592653589793238462643383279502884;
const double eps = 1e-7;
const string something_very_long = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
const string govno = "g";
string impossible = "-1";

void printout(string str)
{
	cout << str;
	exit(0);
}

void Impossible()
{
	printout(impossible);
}

void print(char x, int numb)
{
	for (int i = 0; i < numb; ++i)
		cout << x;
}

int n, m, L, S, T;
vector<ll> edges[maxn];
vector<ll> weights[maxn];
vector<ll> numbers[maxn];
ll distances[maxn];
ll distances2[maxn];

void set_edge_len(int v, int numb, ll val)
{
	weights[v][numb] = val;
	weights[edges[v][numb]][numbers[v][numb]] = val;
}

void update(int v, int numb, ll* dist, priority_queue<pll> q)
{
	if (dist[edges[v][numb]] > dist[v] + weights[v][numb])
		dist[edges[v][numb]] = dist[v] + weights[v][numb], q.push(pll(-dist[edges[v][numb]], edges[v][numb]));
}

void say_yes()
{
	cout << "YES\n";
	for (int i = 0; i < maxn; ++i)
		for (int j = 0; j < edges[i].size(); ++j)
			if (i < edges[i][j])
				cout << i << ' ' << edges[i][j] << ' ' << ((weights[i][j] == 0) ? (ll)1e15 : weights[i][j]) << '\n';
	exit(0);
}

void say_no()
{
	printout("NO");
}

int main()
{
	fill(distances, distances + maxn, inf);
	fill(distances2, distances2 + maxn, inf);
	cin >> n >> m >> L >> S >> T;
	for (int i = 0; i < m; ++i)
	{
		int x, y, w;
		cin >> x >> y >> w;
		edges[x].push_back(y);
		edges[y].push_back(x);
		weights[x].push_back(w);
		weights[y].push_back(w);
		numbers[x].push_back(edges[y].size() - 1);
		numbers[y].push_back(edges[x].size() - 1);
	}
	priority_queue<pair<ll, ll>> q;
	q.push(pll(0, S));
	distances[S] = 0;
	while (!q.empty())
	{
		pll cur_pair = q.top();
		q.pop();
		ll cur_elem = cur_pair.ss;
		if (distances[cur_elem] != -cur_pair.ff)
			continue;
		for (int i = 0; i < edges[cur_elem].size(); ++i)
			if (weights[cur_elem][i] != 0)
				update(cur_elem, i, distances, q);
	}
	if (distances[T] == L)
		say_yes();
	if (distances[T] < L)
		say_no();

	// here solution starts
	q.push(pll(0, T));
	distances2[T] = 0;
	bool f = false;
	while (!q.empty())
	{
		pll cur_pair = q.top();
		q.pop();
		ll cur_elem = cur_pair.ss;
		if (distances2[cur_elem] != -cur_pair.ff)
			continue;
		for (int i = 0; i < edges[cur_elem].size(); ++i)
		{
			ll next = edges[cur_elem][i];
			ll next_dist = weights[cur_elem][i];
			if (next_dist == 0)
			{
				if (distances[next] == inf)
				{
					set_edge_len(cur_elem, i, 1);
					if (distances2[cur_elem] + 1 < distances2[next])
					{
						distances2[next] = distances2[cur_elem] + 1;
						q.push(pll(-distances2[next], next));
					}
				}
				else
				{
					weights[cur_elem][i] = max((ll)1, L - distances2[cur_elem] - distances[next]);
					weights[next][numbers[cur_elem][i]] = max((ll)1, L - distances2[cur_elem] - distances[next]);
					if (L - distances2[cur_elem] - distances[next] >= 1)
					{
						f = true;
						break;
					}
					if (distances2[cur_elem] + weights[cur_elem][i] < distances2[next])
					{
						distances2[next] = distances2[cur_elem] + weights[cur_elem][i];
						q.push(pll(-distances2[next], next));
					}
				}
			}
			else if (distances2[next] >= distances2[cur_elem] + next_dist)
			{
				distances2[next] = distances2[cur_elem] + next_dist;
				q.push(pll(-distances2[next], next));
			}
		}
		if (f)
			break;
	}

	if (f)
		say_yes();
	else
		say_no();
	return 0;
}
/*

*/


#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <math.h>
#include <map>
#include <set>
#include <stdio.h>
#include <stack>
#include <unordered_map>
#define ll long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pib pair<int, bool>
#define pdd pair<double, double>
#define pss pair<string, string>
#pragma comment(linker, "/STACK:251777215")
using namespace std;

const ll maxn = 1011;
const ll maxm = 10001;
const ll maxk = 1001;
const ll maxq = 1000001;
const ll margin = 1001;
const ll maxseg = 262144;
const ll secret_number = -87468267;
const pii secret_pair = make_pair(secret_number, secret_number);
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const int iinf = 2147483647 / 2;
const double pi = 3.141592653589793238462643383279502884;
const double eps = 1e-7;
const string something_very_long = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
const string govno = "g";
string impossible = "-1";

void printout(string str)
{
	cout << str;
	exit(0);
}

void Impossible()
{
	printout(impossible);
}

void print(char x, int numb)
{
	for (int i = 0; i < numb; ++i)
		cout << x;
}

int n, m, L, S, T;
vector<ll> edges[maxn];
vector<ll> weights[maxn];
vector<ll> numbers[maxn];
ll distances[maxn];
ll distances2[maxn];

void set_edge_len(int v, int numb, ll val)
{
	weights[v][numb] = val;
	weights[edges[v][numb]][numbers[v][numb]] = val;
}

void update(int v, int numb, ll* dist, priority_queue<pll> &q)
{
	if (dist[edges[v][numb]] > dist[v] + weights[v][numb])
	{
		dist[edges[v][numb]] = dist[v] + weights[v][numb];
		q.push(pll(-dist[edges[v][numb]], edges[v][numb]));
	}
}

void say_yes()
{
	cout << "YES\n";
	for (int i = 0; i < maxn; ++i)
		for (int j = 0; j < edges[i].size(); ++j)
			if (i < edges[i][j])
				cout << i << ' ' << edges[i][j] << ' ' << ((weights[i][j] == 0) ? (ll)1e15 : weights[i][j]) << '\n';
	exit(0);
}

void say_no()
{
	printout("NO");
}

int main()
{
	fill(distances, distances + maxn, inf);
	fill(distances2, distances2 + maxn, inf);
	cin >> n >> m >> L >> S >> T;
	for (int i = 0; i < m; ++i)
	{
		int x, y, w;
		cin >> x >> y >> w;
		edges[x].push_back(y);
		edges[y].push_back(x);
		weights[x].push_back(w);
		weights[y].push_back(w);
		numbers[x].push_back(edges[y].size() - 1);
		numbers[y].push_back(edges[x].size() - 1);
	}
	priority_queue<pair<ll, ll>> q;
	q.push(pll(0, S));
	distances[S] = 0;
	while (!q.empty())
	{
		pll cur_pair = q.top();
		q.pop();
		ll cur_elem = cur_pair.ss;
		if (distances[cur_elem] != -cur_pair.ff)
			continue;
		for (int i = 0; i < edges[cur_elem].size(); ++i)
			if (weights[cur_elem][i] != 0)
				update(cur_elem, i, distances, q);
	}
	if (distances[T] == L)
		say_yes();
	if (distances[T] < L)
		say_no();

	// here solution starts
	q.push(pll(0, T));
	distances2[T] = 0;
	bool f = false;
	while (!q.empty())
	{
		pll cur_pair = q.top();
		q.pop();
		ll cur_elem = cur_pair.ss;
		if (distances2[cur_elem] != -cur_pair.ff)
			continue;
		for (int i = 0; i < edges[cur_elem].size(); ++i)
		{
			ll next = edges[cur_elem][i];
			ll next_dist = weights[cur_elem][i];
			if (next_dist == 0)
			{
				if (distances[next] == inf)
				{
					set_edge_len(cur_elem, i, 1);
					if (distances2[cur_elem] + 1 < distances2[next])
					{
						distances2[next] = distances2[cur_elem] + 1;
						q.push(pll(-distances2[next], next));
					}
				}
				else
				{
					weights[cur_elem][i] = max((ll)1, L - distances2[cur_elem] - distances[next]);
					weights[next][numbers[cur_elem][i]] = max((ll)1, L - distances2[cur_elem] - distances[next]);
					if (L - distances2[cur_elem] - distances[next] >= 1)
					{
						f = true;
						break;
					}
					if (distances2[cur_elem] + weights[cur_elem][i] < distances2[next])
					{
						distances2[next] = distances2[cur_elem] + weights[cur_elem][i];
						q.push(pll(-distances2[next], next));
					}
				}
			}
			else if (distances2[next] >= distances2[cur_elem] + next_dist)
			{
				distances2[next] = distances2[cur_elem] + next_dist;
				q.push(pll(-distances2[next], next));
			}
		}
		if (f)
			break;
	}

	if (f)
		say_yes();
	else
		say_no();
	return 0;
}
/*

*/


#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <math.h>
#include <map>
#include <set>
#include <stdio.h>
#include <stack>
#include <unordered_map>
#define ll long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pib pair<int, bool>
#define pdd pair<double, double>
#define pss pair<string, string>
#pragma comment(linker, "/STACK:251777215")
using namespace std;

const ll maxn = 1011;
const ll maxm = 10001;
const ll maxk = 1001;
const ll maxq = 1000001;
const ll margin = 1001;
const ll maxseg = 262144;
const ll secret_number = -87468267;
const pii secret_pair = make_pair(secret_number, secret_number);
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const int iinf = 2147483647 / 2;
const double pi = 3.141592653589793238462643383279502884;
const double eps = 1e-7;
const string something_very_long = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
const string govno = "g";
string impossible = "-1";

void printout(string str)
{
	cout << str;
	exit(0);
}

void Impossible()
{
	printout(impossible);
}

void print(char x, int numb)
{
	for (int i = 0; i < numb; ++i)
		cout << x;
}

int n, m, L, S, T;
vector<ll> edges[maxn];
vector<ll> weights[maxn];
vector<ll> numbers[maxn];
ll distances[maxn];
ll distances2[maxn];

void set_edge_len(int v, int numb, ll val)
{
	weights[v][numb] = val;
	weights[edges[v][numb]][numbers[v][numb]] = val;
}

void say_yes()
{
	cout << "YES\n";
	map<pii, ll> weightes;
	for (int i = 0; i < maxn; ++i)
		for (int j = 0; j < edges[i].size(); ++j)
		{
			pii p = (i <= edges[i][j]) ? pii(i, edges[i][j]) : pii(edges[i][j], i);
			weightes[p] = (weights[i][j] == 0) ? 1e15 : weights[i][edges[i][j]];
		}
	for (auto it = weightes.begin(); it != weightes.end(); it++)
	{
		cout << it->first.first << ' ' << it->first.second << ' ' << it->second << '\n';
	}
	exit(0);
}

void say_no()
{
	printout("NO");
}

int main()
{
	for (int i = 0; i < maxn; ++i)
		distances[i] = inf;
	for (int i = 0; i < maxn; ++i)
		distances2[i] = inf;
	cin >> n >> m >> L >> S >> T;
	for (int i = 0; i < m; ++i)
	{
		int x, y, w;
		cin >> x >> y >> w;
		edges[x].push_back(y);
		edges[y].push_back(x);
		weights[x].push_back(w);
		weights[y].push_back(w);
		numbers[x].push_back(edges[y].size() - 1);
		numbers[y].push_back(edges[x].size() - 1);
	}
	priority_queue<pair<ll, ll>> q;
	q.push(pll(0, S));
	distances[S] = 0;
	while (!q.empty())
	{
		pll cur_pair = q.top();
		q.pop();
		ll cur_elem = cur_pair.ss;
		if (distances[cur_elem] != -cur_pair.ff)
			continue;
		for (int i = 0; i < edges[cur_elem].size(); ++i)
		{
			ll next = edges[cur_elem][i];
			ll next_dist = weights[cur_elem][i];
			if (next_dist == 0)
				continue;
			if (distances[next] > distances[cur_elem] + next_dist)
			{
				distances[next] = distances[cur_elem] + next_dist;
				q.push(pll(-distances[next], next));
			}
		}
	}
	if (distances[T] == L)
		say_yes();
	if (distances[T] < L)
		say_no();

	// here solution starts
	q.push(pll(0, T));
	distances2[T] = 0;
	bool f = false;
	while (!q.empty())
	{
		pll cur_pair = q.top();
		q.pop();
		ll cur_elem = cur_pair.ss;
		if (distances2[cur_elem] != -cur_pair.ff)
			continue;
		for (int i = 0; i < edges[cur_elem].size(); ++i)
		{
			ll next = edges[cur_elem][i];
			ll next_dist = weights[cur_elem][i];
			if (next_dist == 0)
			{
				if (distances[next] == inf)
				{
					weights[cur_elem][i] = 1;
					weights[next][numbers[cur_elem][i]] = 1;
					if (distances2[cur_elem] + 1 < distances2[next])
					{
						distances2[next] = distances2[cur_elem] + 1;
						q.push(pll(-distances2[next], next));
					}
				}
				else
				{
					weights[cur_elem][i] = max((ll)1, L - distances2[cur_elem] - distances[next]);
					weights[next][numbers[cur_elem][i]] = max((ll)1, L - distances2[cur_elem] - distances[next]);
					if (L - distances2[cur_elem] - distances[next] >= 1)
					{
						f = true;
						break;
					}
					if (distances2[cur_elem] + weights[cur_elem][i] < distances2[next])
					{
						distances2[next] = distances2[cur_elem] + weights[cur_elem][i];
						q.push(pll(-distances2[next], next));
					}
				}
			}
			else if (distances2[next] >= distances2[cur_elem] + next_dist)
			{
				distances2[next] = distances2[cur_elem] + next_dist;
				q.push(pll(-distances2[next], next));
			}
		}
		if (f)
			break;
	}

	if (f)
		say_yes();
	else
		say_no();
	return 0;
}
/*

*/


#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

vector<vector<pair<ll,ll>>> adj;
vector<ll> dist;
vector<pair<pair<ll,ll>,ll>> edge;
map<pair<ll,ll>,ll> edgeno;
ll n,m,s,t,l;

void dijkstra(ll val,ll max)
{
      dist.assign(n,1e18);
      dist[s]=0;
      priority_queue<pair<ll,ll>> q;
          q.push({0,s});
          pair<ll,ll> temp;
          while(!q.empty())
          {
                temp=q.top();
                q.pop();
                for(auto h:adj[temp.se])
                {
                      if(h.se==0)
                      {
                            if(edgeno[{h.fi,temp.se}]<=max) h.se=val;
                            else h.se=1e18;
                      }
                      if(dist[h.fi]>dist[temp.se]+h.se)
                      {
                              dist[h.fi]=dist[temp.se]+h.se;
                            q.push({-dist[h.fi],h.fi});
                      }
                }

          }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,f=0,j,ans=0,k,x,r,u,v;
    cin >> n >> m >> l >> s >> t ;
    adj.resize(n);
    dist.resize(n);

    rep(i,m)
    {
          cin >> u >> v >> x ;

          adj[u].pb({v,x});
          adj[v].pb({u,x});
          edge.pb({{u,v},x});
          edgeno[{u,v}]=i;
          edgeno[{v,u}]=i;
    }
    dijkstra(0,-1);
    if(dist[t]<l)
    {
          cout << "NO" << endl ;
          return 0;
    }
    dijkstra(1,m-1);
    if(dist[t]>l)
    {
          cout << "NO" << endl ;
          return 0;
    }
    ll left=0;
    r=m-1;
    ll mid;
    while(left<r)
    {
          mid=(r-left)/2+left;
          dijkstra(1,mid);
          if(dist[t]>l) left=mid+1;
          else r=mid;
    }
    //cout << left << endl;
    dijkstra(1,left);
    if(edge[left].se==0) edge[left].se=l-dist[t]+1;
    cout <<"YES" << endl;
    rep(i,m)
    {
          cout<< edge[i].fi.fi << " " << edge[i].fi.se << " " ;
          if(edge[i].se==0)
          {
                if(i<left) edge[i].se=1;
                else edge[i].se=1e18;
          }
          cout << edge[i].se << endl;
    }

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

vector<vector<pair<ll,ll>>> adj;
vector<ll> dist;
vector<pair<pair<ll,ll>,ll>> res;
map<pair<ll,ll>,ll> edge;
ll n;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll m,i,f=0,j,ans=0,k,x,r,l,t,s,u,v;
    cin >> n >> m >> l >> s >> t ;
    adj.resize(n);
    dist.resize(n);

    rep(i,m)
    {
          cin >> u >> v >> x ;
          if(x==0) x=-1;
          res.pb({{u,v},x});
          adj[u].pb({v,x});
          adj[v].pb({u,x});
          if(v>u) edge[{u,v}]=i;
          else edge[{v,u}]=i;
    }
    vector<ll> d(n,1e18);
    d[t]=0;
    priority_queue<pair<ll,ll>> q;
    q.push({0,t});
    pair<ll,ll> temp;
    while(!q.empty())
    {
          temp=q.top();
          q.pop();
          for(auto h:adj[temp.se])
          {
                if(d[h.fi]>d[temp.se]+abs(h.se))
                {
                        d[h.fi]=d[temp.se]+abs(h.se);
                      q.push({-d[h.fi],h.fi});
                }
          }

    }
    q.push({0,s});
    vector<ll> d1(n,1e18);
    d1[s]=0;
    while(!q.empty())
    {
          temp=q.top();
          q.pop();
          for(auto h:adj[temp.se])
          {

                if(d1[h.fi]>d1[temp.se]+abs(h.se))
                {
                     //cout << temp.se << " " << h.fi << " " << h.se << endl ;
                     if(h.se==-1)
                      {
                            if(d1[temp.se]+1+d[h.fi]<l)
                            {

                                  h.se=l-d[h.fi]-d1[temp.se];
                                  res[edge[{std::min(temp.se,h.fi),std::max(temp.se,h.fi)}]].se=h.se;
                                  //cout << h.se << endl ;

                            }
                      }
                      d1[h.fi]=d1[temp.se]+abs(h.se);
                      q.push({-d1[h.fi],h.fi});
                }
          }

    }
    //rep(i,n) cout << d1[i] << " " ;
    //cout << endl ;

   if(d1[t]!=l)
   {
         cout << "NO" ;
         return 0;
   }

    cout << "YES" << endl ;
    rep(i,res.size())
          {
                cout << res[i].fi.fi << " "  <<res[i].fi.se<< " " << res[i].se << endl ;

          }

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

vector<vector<pair<ll,ll>>> adj;
vector<ll> dist;
vector<pair<pair<ll,ll>,ll>> res;
map<pair<ll,ll>,ll> edge;
ll n;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll m,i,f=0,j,ans=0,k,x,r,l,t,s,u,v;
    cin >> n >> m >> l >> s >> t ;
    adj.resize(n);
    dist.resize(n);

    rep(i,m)
    {
          cin >> u >> v >> x ;
          if(x==0) x=-1;
          res.pb({{u,v},x});
          adj[u].pb({v,x});
          adj[v].pb({u,x});
          if(v>u) edge[{u,v}]=i;
          else edge[{v,u}]=i;
    }
    vector<ll> d(n,1e18);
    d[t]=0;
    priority_queue<pair<ll,ll>> q;
    q.push({0,t});
    pair<ll,ll> temp;
    while(!q.empty())
    {
          temp=q.top();
          q.pop();
          for(auto h:adj[temp.se])
          {
                if(d[h.fi]>d[temp.se]+abs(h.se))
                {
                        d[h.fi]=d[temp.se]+abs(h.se);
                      q.push({-d[h.fi],h.fi});
                }
          }

    }
    q.push({0,s});
    vector<ll> d1(n,1e18);
    d1[s]=0;
    while(!q.empty())
    {
          temp=q.top();
          q.pop();
          for(auto h:adj[temp.se])
          {

                if(d1[h.fi]>d1[temp.se]+abs(h.se))
                {
                     //cout << temp.se << " " << h.fi << " " << h.se << endl ;
                     if(h.se==-1)
                      {
                            if(d1[temp.se]+1+d[h.fi]<l)
                            {

                                  h.se=l-d[h.fi]-d1[temp.se];
                                  res[edge[{std::min(temp.se,h.fi),std::max(temp.se,h.fi)}]].se=h.se;
                                  //cout << h.se << endl ;

                            }
                      }
                      d1[h.fi]=d1[temp.se]+abs(h.se);
                      q.push({-d1[h.fi],h.fi});
                }
          }

    }
    //rep(i,n) cout << d1[i] << " " ;
    //cout << endl ;

   if(d1[t]!=l)
   {
         cout << "NO" ;
         return 0;
   }

    cout << "YES" << endl ;
    rep(i,res.size())
          {
                cout << res[i].fi.fi << " "  <<res[i].fi.se<< " " ;
                if(res[i].se==-1) res[i].se=1e18;
                cout << res[i].se ;
                cout << endl ;

          }

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll m,n,i,f=0,j,ans=0,k,x,r,l,t,s,u,v;
    cin >> n >> m >> l >> s >> t ;
    vector<vector<pair<ll,ll>>> adj(n);
    map<pair<ll,ll>,ll> edge;
    vector<pair<pair<ll,ll>,ll>> res;
    rep(i,m)
    {
          cin >> u >> v >> x ;
          if(x==0) x=1e18;
          res.pb({{u,v},x});
          adj[u].pb({v,x});
          adj[v].pb({u,x});
          if(v>u) edge[{u,v}]=i+1;
          else edge[{v,u}]=i+1;
    }
    vector<ll> d(n,1e18),parent(n,-1);
    d[s]=0;
    priority_queue<pair<ll,ll>> q;
    q.push({0,s});
    pair<ll,ll> temp;
    while(!q.empty())
    {
          temp=q.top();
          q.pop();
          for(auto h:adj[temp.se])
          {
                if(d[h.fi]>d[temp.se]+h.se)
                {
                      parent[h.fi]=temp.se;
                      d[h.fi]=d[temp.se]+h.se;
                      q.push({-d[h.fi],h.fi});
                }
          }

    }
    if(d[t]<l)
    {

          cout << "NO" ;
          return 0;
    }
    if(d[t]==l)
    {
          cout << "YES" << endl ;
          rep(i,res.size())
          {
                cout << res[i].fi.fi << " "  <<res[i].fi.se<< " " << res[i].se << endl ;

          }
          return 0 ;
    }
    q.push({0,s});
    vector<ll> d1(n,1e18);
    d1[s]=0;
    while(!q.empty())
    {
          temp=q.top();
          q.pop();
          for(auto h:adj[temp.se])
          {
                if(h.se==1e18) h.se=0;
                if(d1[h.fi]>d1[temp.se]+h.se)
                {
                      parent[h.fi]=temp.se;
                      d1[h.fi]=d1[temp.se]+h.se;
                      q.push({-d1[h.fi],h.fi});
                }
          }

    }
    //cout << d1[t] << endl ;
    if(d1[t]>l)
    {
          cout << "NO" ;
          return 0;
    }
    vector<ll> zerow;
    ll zeros =0;
    x=t;
    for(;x!=s;x=parent[x])
    {
          if(d1[x]==d1[parent[x]])
          {
                if(x>parent[x]) zerow.pb(edge[{parent[x],x}]);
                else zerow.pb(edge[{x,parent[x]}]);
                zeros++;
          }
    }
    //cout << l << " " << d[t] << " " << zeros << endl ;
    if(l-d1[t]<zeros)
    {
          //cout << 1 << endl ;
          cout << "NO" ;
          return 0;
    }
    if(zeros==0)
    {
        if(l==d1[t])
        {
            cout << "YES" << endl ;
            rep(i,res.size())
          {
                cout << res[i].fi.fi << " "  <<res[i].fi.se<< " " << res[i].se << endl ;

          }
          return 0 ;
        }
        else
        {
            cout << "NO" ;
            return 0;
        }
    }
    res[zerow[0]-1].se=l-d1[t]-zeros+1;
    for(i=1;i<zerow.size();++i)
    res[zerow[i]].se=1;
    cout << "YES" << endl ;
    rep(i,res.size())
    {
          cout << res[i].fi.fi << " " << res[i].fi.se << " " ;
          if(res[i].se==0) cout << 1e18 << endl ;
          else cout << res[i].se << endl ;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
// Order Statistic Tree
/* Special functions:

		find_by_order(k) --> returns iterator to the kth largest element counting from 0
		order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
/******   END OF HEADER *********/
#define SIZE 100009
long long n, aAr[SIZE], pAr[SIZE];
vector<long long> children[SIZE];
long long height[SIZE], oddCnt[SIZE*100], evenCnt[SIZE*100], xorVal, ans;
long long oddNodeCnt, evenNodeCnt;
void up(long long u)
{
    long long cur = u, h = 1;
    while(cur && height[cur]==0)
    {
        height[cur] = h++;
        cur = pAr[cur];
    }
}
int main()
{
//    freopen("input.txt", "r", stdin);
    long long a, b, c, d, e, f;
    cin >> n;
    for (a = 1; a <= n; a++)
    {
        scanf("%lld", &aAr[a]);
    }
    for ( a= 2; a <= n; a++)
    {
        scanf("%lld", &pAr[a]);
        children[pAr[a]].push_back( a );
    }
    for (a = 1; a <= n; a++)
    {
        if (  children[a].size() == 0 )
        {
            up(a);
        }
    }
    for (a = 1; a <= n; a++)
    {
        if ( height[a] & 1 ) // odd node
        {
            xorVal ^= aAr[a];
            oddCnt[ aAr[a] ]++;
            oddNodeCnt++;
        }
        else
        {
            evenCnt[ aAr[a] ]++;
            evenNodeCnt++;
        }
    }
    for (a = 1; a <= n; a++)
    {
        if ( height[a] & 1  ) // odd node
        {
            long long newXorVal = xorVal ^ aAr[a];
            ans += evenCnt[ newXorVal ];
        }
    }
    if ( xorVal == 0 ) // Sagheer already winning
    {
        ans += oddNodeCnt * (oddNodeCnt-1);
        ans += evenNodeCnt * (evenNodeCnt-1);
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main ()
{
    int n;
    cin>>n;
    vector<int> c(n), p(n,0);

    for (int i=0; i<n; i++)
        cin>>c[i];

    for (int i=1; i<n; i++)
        cin>>p[i],
        p[i]--;

    vector<vector<int> > child(n);

    for (int i=1; i<n; i++)
        child[p[i]].push_back(i);

    vector<int> col(n,0);
    col[0]=1;
    vector<int> q;
    q.push_back(0);
    int depth=1;

    for (int i=0; i<q.size(); i++)
    {
        for (auto j: child[q[i]])
            if (!col[j])
                q.push_back(j),
                col[j]=1+col[q[i]],
                depth=max(depth, col[j]);
    }

    multiset<int> even, odd;
    int xorsum=0;
    for (int i=0; i<n; i++)
        if (col[i]%2==depth%2)
            odd.insert(c[i]),
            xorsum^=c[i];
        else
            even.insert(c[i]);

    long long swaps=0;
    if (xorsum==0)
    {
        long long a=odd.size();
        long long b=even.size();
        swaps=a*(a-1)/2+b*(b-1)/2;
    }
    for (auto i:odd)
        swaps+=even.count(xorsum^i);
    cout<<swaps;

}


#include <bits/stdc++.h>
using namespace std;

int main ()
{
    int n;
    cin>>n;
    vector<int> c(n), p(n,0);

    for (int i=0; i<n; i++)
        cin>>c[i];

    for (int i=1; i<n; i++)
        cin>>p[i],
        p[i]--;

    vector<vector<int> > child(n);

    for (int i=1; i<n; i++)
        child[p[i]].push_back(i);

    vector<int> col(n,0);
    col[0]=1;
    vector<int> q;
    q.push_back(0);
    int depth=1;

    for (int i=0; i<q.size(); i++)
    {
        for (auto j: child[q[i]])
            if (!col[j])
                q.push_back(j),
                col[j]=1+col[q[i]],
                depth=max(depth, col[j]);
    }

    multiset<int> even, odd;
    int xorsum=0;
    for (int i=0; i<n; i++)
        if (col[i]%2==depth%2)
            odd.insert(c[i]),
            xorsum^=c[i];
        else
            even.insert(c[i]);

    long long swaps=0;
    if (xorsum==0)
    {
        long long a=odd.size();
        long long b=even.size();
        cout<<a*(a-1)/2+b*(b-1)/2<<endl;
        return 0;
    }
    for (auto i:odd)
        swaps+=even.count(xorsum^i);
    cout<<swaps;

}


#include <bits/stdc++.h>
using namespace std;

int main ()
{
    int n;
    cin>>n;
    vector<int> c(n), p(n,0);

    for (int i=0; i<n; i++)
        cin>>c[i];

    for (int i=1; i<n; i++)
        cin>>p[i],
        p[i]--;

    vector<vector<int> > child(n);

    for (int i=1; i<n; i++)
        child[p[i]].push_back(i);

    vector<int> col(n,0);
    col[0]=1;
    vector<int> q;
    q.push_back(0);
    int depth=1;

    for (int i=0; i<q.size(); i++)
    {
        for (auto j: child[q[i]])
            if (!col[j])
                q.push_back(j),
                col[j]=1+col[q[i]],
                depth=max(depth, col[j]);
    }

    multiset<int> even, odd;
    int xorsum=0;
    for (int i=0; i<n; i++)
        if (col[i]%2==depth%2)
            odd.insert(c[i]),
            xorsum^=c[i];
        else
            even.insert(c[i]);

    long long swaps=0;
    for (auto i:odd)
        swaps+=even.count(xorsum^i);
    cout<<swaps;

}


#include <bits/stdc++.h>
using namespace std;

int main ()
{
    int n;
    cin>>n;
    vector<int> c(n), p(n,0);

    for (int i=0; i<n; i++)
        cin>>c[i];

    for (int i=1; i<n; i++)
        cin>>p[i],
        p[i]--;

    vector<vector<int> > child(n);

    for (int i=1; i<n; i++)
        child[p[i]].push_back(i);

    vector<int> col(n,0);
    col[0]=1;
    vector<int> q;
    q.push_back(0);
    int depth=1;

    for (int i=0; i<q.size(); i++)
    {
        for (auto j: child[q[i]])
            if (!col[j])
                q.push_back(j),
                col[j]=1+col[q[i]],
                depth=max(depth, col[j]);
    }

    multiset<int> even, odd;
    int xorsum=0;
    for (int i=0; i<n; i++)
        if (col[i]%2==depth%2)
            odd.insert(c[i]),
            xorsum^=c[i];
        else
            even.insert(c[i]);

    long long swaps=0;
    if (xorsum==0)
    {
        long long a=odd.size();
        long long b=even.size();
        swaps=a*(a-1)/2+b*(b-1)/2;
    }

    vector<int> freq(20000001,0);
    for (auto i:even)
        freq[i]++;

    for (auto i: odd)
        swaps+=freq[xorsum^i];
    cout<<swaps;

}


#include <bits/stdc++.h>

using namespace std;
int n;
struct node {
	int father;
	//vector<int> sons;
	int value;
	int r;
} nodes[200000];

vector<int> veca;
//map<int, int> mapa;
map<int, int> mapb;

int ifnotleaf[200000];

void dfs(int nowpos, int nowr) {
	if (nowpos == 0)
		return;
	if (nodes[nowpos].r)
		return;
	nodes[nowpos].r = nowr;
	if (nowr == 2)
		nowr = 1;
	else
		nowr = 2;
	dfs(nodes[nowpos].father, nowr);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &nodes[i].value);
	}

	for (int i = 2; i <= n; i++) {
		scanf("%d", &nodes[i].father);
		ifnotleaf[nodes[i].father] = 1;
	}

	int sumr = 0;
	for (int i = 1; i <= n; i++) {
		if (ifnotleaf[i] == 0) {
			dfs(i, 2);
		}
	}

	for (int i = 1; i <= n; i++) {
		if (nodes[i].r == 1) {
			veca.push_back(nodes[i].value);
		} else {
			mapb[nodes[i].value]++;
			sumr ^= nodes[i].value;
		}
	}

	long long ansa = 0;
	for (int au : veca) {
		auto it = mapb.find(au ^ sumr);
		if (it == mapb.end())
			continue;
		ansa += it->second;
	}
	if (sumr == 0)
		ansa++;
	printf("%I64d\n", ansa);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n;
struct node {
	int father;
	//vector<int> sons;
	int value;
	int r;
} nodes[200000];

vector<int> veca;
//map<int, int> mapa;
map<int, int> mapb;

int ifnotleaf[200000];

void dfs(int nowpos, int nowr) {
	if (nowpos == 0)
		return;
	if (nodes[nowpos].r)
		return;
	nodes[nowpos].r = nowr;
	if (nowr == 2)
		nowr = 1;
	else
		nowr = 2;
	dfs(nodes[nowpos].father, nowr);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &nodes[i].value);
	}

	for (int i = 2; i <= n; i++) {
		scanf("%d", &nodes[i].father);
		ifnotleaf[nodes[i].father] = 1;
	}

	for (int i = 1; i <= n; i++) {
		if (ifnotleaf[i] == 0) {
			dfs(i, 2);
		}
	}

	int sumr = 0;
	for (int i = 1; i <= n; i++) {
		if (nodes[i].r == 1) {
			mapb[nodes[i].value]++;
		} else {
			veca.push_back(nodes[i].value);
			sumr ^= nodes[i].value;
		}
	}

	long long ansa = 0;
	for (int au : veca) {
		auto it = mapb.find(au ^ sumr);
		if (it == mapb.end())
			continue;
		ansa += it->second;
	}
	if (sumr == 0) {
		ansa += 1ll * veca.size() * (veca.size() - 1) / 2;
		ansa += 1ll * mapb.size() * (mapb.size() - 1) / 2;
	}
	printf("%I64d\n", ansa);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n;
struct node {
	int father;
	//vector<int> sons;
	int value;
	int r;
} nodes[200000];

vector<int> veca;
//map<int, int> mapa;
map<int, int> mapb;
int sizb;

int ifnotleaf[200000];

void dfs(int nowpos, int nowr) {
	if (nowpos == 0)
		return;
	if (nodes[nowpos].r)
		return;
	nodes[nowpos].r = nowr;
	if (nowr == 2)
		nowr = 1;
	else
		nowr = 2;
	dfs(nodes[nowpos].father, nowr);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &nodes[i].value);
	}

	for (int i = 2; i <= n; i++) {
		scanf("%d", &nodes[i].father);
		ifnotleaf[nodes[i].father] = 1;
	}

	for (int i = 1; i <= n; i++) {
		if (ifnotleaf[i] == 0) {
			dfs(i, 2);
		}
	}

	int sumr = 0;
	for (int i = 1; i <= n; i++) {
		if (nodes[i].r == 1) {
			mapb[nodes[i].value]++;
			sizb++;
		} else {
			veca.push_back(nodes[i].value);
			sumr ^= nodes[i].value;
		}
	}

	long long ansa = 0;
	for (int au : veca) {
		auto it = mapb.find(au ^ sumr);
		if (it == mapb.end())
			continue;
		ansa += it->second;
	}
	if (sumr == 0) {
		ansa += 1ll * veca.size() * (veca.size() - 1) / 2;
		ansa += 1ll * sizb * (sizb - 1) / 2;
	}
	printf("%I64d\n", ansa);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n;
struct node {
	int father;
	//vector<int> sons;
	int value;
	int r;
} nodes[200000];

vector<int> veca;
//map<int, int> mapa;
map<int, int> mapb;

int ifnotleaf[200000];

void dfs(int nowpos, int nowr) {
	if (nowpos == 0)
		return;
	if (nodes[nowpos].r)
		return;
	nodes[nowpos].r = nowr;
	if (nowr == 2)
		nowr = 1;
	else
		nowr = 2;
	dfs(nodes[nowpos].father, nowr);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &nodes[i].value);
	}

	for (int i = 2; i <= n; i++) {
		scanf("%d", &nodes[i].father);
		ifnotleaf[nodes[i].father] = 1;
	}

	for (int i = 1; i <= n; i++) {
		if (ifnotleaf[i] == 0) {
			dfs(i, 2);
		}
	}

	int sumr = 0;
	for (int i = 1; i <= n; i++) {
		if (nodes[i].r == 1) {
			mapb[nodes[i].value]++;
		} else {
			veca.push_back(nodes[i].value);
			sumr ^= nodes[i].value;
		}
	}

	long long ansa = 0;
	for (int au : veca) {
		auto it = mapb.find(au ^ sumr);
		if (it == mapb.end())
			continue;
		ansa += it->second;
	}
	if (sumr == 0)
		ansa++;
	printf("%I64d\n", ansa);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using LL = long long;

const int N = 100100;

vector <int> G[N];
int d[N], a[N], ans, rsv;

void dfs(int u, int p) {
  d[u] = 1;
  for (auto v : G[u]) {
    if (v == p) continue;
    dfs(v, u);
    d[u] = max(d[v] + 1, d[u]);
  }
  if (d[u] & 1) ans ^= a[u];
  else rsv ^= a[u];
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i ++)
    scanf("%d", a + i);
  for (int i = 2; i <= n; i ++) {
    int p;
    scanf("%d", &p);
    G[p].push_back(i);
  }
  dfs(1, 0);
  if (! (rsv ^ ans)) {
    puts("0"); return 0;
  }
  map <int, int> cnt;
  for (int i = 1; i <= n; i ++)
    if (d[i] & 1) cnt[ans ^ a[i]] ++;
  LL res = 0;
  for (int i = 1; i <= n; i ++)
    if (~ d[i] & 1) res += cnt[a[i]];
  cout << res << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using LL = long long;

const int N = 100100;

vector <int> G[N];
int d[N], a[N], ans, rsv;

void dfs(int u, int p) {
  d[u] = 1;
  for (auto v : G[u]) {
    if (v == p) continue;
    dfs(v, u);
    d[u] = max(d[v] + 1, d[u]);
  }
  if (d[u] & 1) ans ^= a[u];
  else rsv ^= a[u];
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i ++)
    scanf("%d", a + i);
  for (int i = 2; i <= n; i ++) {
    int p;
    scanf("%d", &p);
    G[p].push_back(i);
  }
  dfs(1, 0);
  if (! rsv ^ ans) {
    puts("0"); return 0;
  }
  map <int, int> cnt;
  for (int i = 1; i <= n; i ++)
    if (d[i] & 1) cnt[ans ^ a[i]] ++;
  LL res = 0;
  for (int i = 1; i <= n; i ++)
    if (~ d[i] & 1) res += cnt[a[i]];
  cout << res << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using LL = long long;

const int N = 100100;

vector <int> G[N];
int d[N], a[N], ans;

void dfs(int u, int p) {
  d[u] = 1;
  for (auto v : G[u]) {
    if (v == p) continue;
    dfs(v, u);
    d[u] = max(d[v] + 1, d[u]);
  }
  if (d[u] & 1) ans ^= a[u];
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i ++)
    scanf("%d", a + i);
  for (int i = 2; i <= n; i ++) {
    int p;
    scanf("%d", &p);
    G[p].push_back(i);
  }
  dfs(1, 0);
  map <int, int> cnt;
  for (int i = 1; i <= n; i ++)
    if (d[i] & 1) cnt[ans ^ a[i]] ++;
  LL res = 0;
  for (int i = 1; i <= n; i ++)
    if (~ d[i] & 1) res += cnt[a[i]];
  cout << res << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using LL = long long;

const int N = 100100;

vector <int> G[N];
int d[N], a[N], ans, rsv, cnt;

void dfs(int u, int p) {
  d[u] = 1;
  for (auto v : G[u]) {
    if (v == p) continue;
    dfs(v, u);
    d[u] = max(d[v] + 1, d[u]);
  }
  if (d[u] & 1) ans ^= a[u], cnt ++;
  else rsv ^= a[u];
}

LL get(LL x) {
  return x * (x - 1) / 2;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i ++)
    scanf("%d", a + i);
  for (int i = 2; i <= n; i ++) {
    int p;
    scanf("%d", &p);
    G[p].push_back(i);
  }
  dfs(1, 0);
  if (! rsv) {
    if (! ans) {
      puts("0"); return 0;
    }
  }
  LL ser = get(cnt) + get(n - cnt);
  map <int, int> cnt;
  for (int i = 1; i <= n; i ++)
    if (d[i] & 1) cnt[ans ^ a[i]] ++;
  LL res = 0;
  for (int i = 1; i <= n; i ++)
    if (~ d[i] & 1) res += cnt[a[i]];
  cout << ((ans ^ rsv) != 0)*res + (ans == 0)*ser << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using LL = long long;

const int N = 100100;

vector <int> G[N];
int d[N], a[N], ans, rsv, cnt;

void dfs(int u, int p) {
  d[u] = 1;
  for (auto v : G[u]) {
    if (v == p) continue;
    dfs(v, u);
    d[u] = max(d[v] + 1, d[u]);
  }
  if (d[u] & 1) ans ^= a[u], cnt ++;
  else rsv ^= a[u];
}

LL get(LL x) {
  return x * (x - 1) / 2;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i ++)
    scanf("%d", a + i);
  for (int i = 2; i <= n; i ++) {
    int p;
    scanf("%d", &p);
    G[p].push_back(i);
  }
  dfs(1, 0);
  LL ser = get(cnt) + get(n - cnt);
  map <int, int> cnt;
  for (int i = 1; i <= n; i ++)
    if (d[i] & 1) cnt[ans ^ a[i]] ++;
  LL res = 0;
  for (int i = 1; i <= n; i ++)
    if (~ d[i] & 1) res += cnt[a[i]];
  cout << res + (ans == 0)*ser << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define debug(n1) cout<<n1<<endl
ll n,a[100005],dist[100005];
vector<ll>adj[100005];
ll o=0, e=0;
ll dmax=0;
map<ll,ll>c;
void dfs(ll i,ll d)
{
	dist[i]=d;
	dmax=max(dmax,d);
	if(d%2==0)e^=a[i];
	else o^=a[i];
	for(auto j:adj[i])
		dfs(j,d+1);
}

int main() {

SPEED;
cin>>n;
for(int i=1;i<=n;i++)
	cin>>a[i];

for(int i=2;i<=n;i++)
{
	ll x;
	cin>>x;
	adj[x].pb(i);
}

dfs(1,0);
ll b=0;
if(dmax%2)
	b=o;
else b=e;
ll cnt2=0;
for(int i=1;i<=n;i++)
	if(dist[i]%2 != dmax%2)
		c[a[i]]++,cnt2++;
ll ans=0;
ll cnt=0;

for(int i=1;i<=n;i++)
	if(dist[i]%2==dmax%2)ans+=c[(a[i]^b)],cnt++;

if(b==0)
	ans=ans+(cnt*(cnt-1))/2+(cnt2*(cnt2-1))/2;
cout<<ans<<endl;
	return 0;
           }


#include <bits/stdc++.h>

using namespace std;

#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define debug(n1) cout<<n1<<endl
ll n,a[100005],dist[100005];
vector<ll>adj[100005];
ll o=0, e=0;
ll dmax=0;
map<ll,ll>c;
void dfs(ll i,ll d)
{
	dist[i]=d;
	dmax=max(dmax,d);
	if(d%2==0)e^=a[i];
	else o^=a[i];
	for(auto j:adj[i])
		dfs(j,d+1);
}

int main() {

SPEED;
cin>>n;
for(int i=1;i<=n;i++)
	cin>>a[i];

for(int i=2;i<=n;i++)
{
	ll x;
	cin>>x;
	adj[x].pb(i);
}

dfs(1,0);
ll b=0;
if(dmax%2)
	b=o;
else b=e;

for(int i=1;i<=n;i++)
	if(dist[i]%2 != dmax%2)
		c[a[i]]++;
ll ans=0;
for(int i=1;i<=n;i++)
	if(dist[i]%2 == dmax%2)ans+=c[(a[i]^b)];
cout<<ans<<endl;
	return 0;
           }


#include <bits/stdc++.h>

using namespace std;

#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define debug(n1) cout<<n1<<endl
ll n,a[100005],dist[100005];
vector<ll>adj[100005];
ll o=0, e=0;
ll dmax=0;
map<ll,ll>c;
void dfs(ll i,ll d)
{
	dist[i]=d;
	dmax=max(dmax,d);
	if(d%2==0)e^=a[i];
	else o^=a[i];
	for(auto j:adj[i])
		dfs(j,d+1);
}

int main() {

SPEED;
cin>>n;
for(int i=1;i<=n;i++)
	cin>>a[i];

for(int i=2;i<=n;i++)
{
	ll x;
	cin>>x;
	adj[x].pb(i);
}

dfs(1,0);
ll b=0;
if(dmax%2)
	b=o;
else b=e;

for(int i=1;i<=n;i++)
	if(dist[i]%2 != dmax%2)
		c[a[i]]++;
ll ans=0;
for(int i=1;i<=n;i++)
	ans+=c[(a[i]^b)];
cout<<ans<<endl;
	return 0;
           }


#include <bits/stdc++.h>

using namespace std;

#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define debug(n1) cout<<n1<<endl
ll n,a[100005],dist[100005];
vector<ll>adj[100005];
ll o=0, e=0;
ll dmax=0;
map<ll,ll>c;
void dfs(ll i,ll d)
{
	dist[i]=d;
	dmax=max(dmax,d);
	if(d%2==0)e^=a[i];
	else o^=a[i];
	for(auto j:adj[i])
		dfs(j,d+1);
}

int main() {

SPEED;
cin>>n;
for(int i=1;i<=n;i++)
	cin>>a[i];

for(int i=2;i<=n;i++)
{
	ll x;
	cin>>x;
	adj[x].pb(i);
}

dfs(1,0);
ll b=0;
if(dmax%2)
	b=o;
else b=e;

for(int i=1;i<=n;i++)
	if(dist[i]%2 != dmax%2)
		c[a[i]]++;
ll ans=0;
ll cnt=0;

for(int i=1;i<=n;i++)
	if(dist[i]%2==dmax%2)ans+=c[(a[i]^b)],cnt++;

if(b==0)
	ans=ans+(cnt*(cnt-1))/2;
cout<<ans<<endl;
	return 0;
           }


/*
ID: kfoozminus
TASK:
LANG: C++
*/

#include <bits/stdc++.h>
using namespace std;
//typedefs
/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <int, pii> piii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> pll;
const double PI = acos(-1);
*/
//typedefs
#define ll long long
#define ull unsigned long long
#define pii pair <int, int>
#define piii pair <int, pii>
#define vi vector <int>
#define vl vector <ll>
#define pll pair <ll, ll>
#define PI acos(-1)
//defines
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define mem(a, b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define SQR(a) ((a)*(a))
#define inf 100000000
#define mod 1000000007
#define mod1 1000000007
#define mod2 1000000009
#define b1 43
#define b2 41
#define EPS 1e-9
//define harmonic(n) 0.57721566490153286l+log(n)
#define nl puts("")
#define odd(n) ((n)&1)
#define even(n) (!((n)&1))
#define vsort(v) sort(v.begin(), v.end())
#define lc (node<<1)
#define rc ((node<<1)|1)
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
//loop
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
//input
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sd(a) scanf("%lf", &a)
#define sc(a) scanf("%c", &a)
#define sst(a) scanf("%s", a)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
//debug
#ifdef kfoozminus

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
	os << "{";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << *it;
	}
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin()) os << ", ";
		os << *it;
	}
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
	}
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
	for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }

#else
#define dbg(args...)
#endif
/*
ll add(ll a, ll b) {
	ll ret = a+b;
	if(ret >= mod) ret -= mod;
	return ret;
}

ll subtract(ll a, ll b) {
	ll ret = a-b;
	if(ret < 0) ret += mod;
	return ret;
}

ll mult(ll a, ll b) {
	ll ret = a*b;
	if(ret >= mod) ret %= mod;
	return ret;
}

ll bigmod(ll a, ll b) {
	ll ret = 1;
	while(b) {
		if(b&1) ret = mult(ret, a);
		b >>= 1; a = mult(a, a);
	}
	return ret;
}
*/

//ll inverse(ll n) { return bigmod(n, mod-2); }

/*
#define PMX 1000000

int marked[PMX/64 + 2];
vi primes;

#define mark(x) marked[x >> 6] |= (1 << ((x & 63) >> 1))
#define check(x) (marked[x >> 6] & (1 << ((x & 63) >> 1)))

bool isPrime(int x)
{
	return (x > 1) && ((x == 2) || ((x & 1) && (!(check(x)))));
}

void seive(int n)
{
	int i, j;
	for(i = 3; i * i <= n; i += 2) if(!check(i)) for(j = i * i; j <= n; j += i << 1) mark(j);
	primes.PB(2);
	for(i = 3; i <= n; i += 2) if(isPrime(i)) primes.PB(i);
}
*/

//Direction Array
//int fx[]={1, -1, 0, 0}; int fy[]={0, 0, 1, -1};
//int fx[]={0, 0, 1, -1, -1, 1, -1, 1}; int fy[]={-1, 1, 0, 0, 1, 1, -1, -1};

//bit manipulation
/*
bool checkBit(int n, int i) { return (n&(1<<i)); }
int setBit(int n, int i) { return (n|(1<<i)); }
int resetBit(int n, int i) { return (n&(~(1<<i))); }
*/
//end of template

#define MX 100007

vector<int> v[3], edge[MX];
int a[MX];

int dfs(int nd)
{
	int ret = 1;
	for(int k = 0; k < edge[nd].size(); k ++) {
		int vv = edge[nd][k];
		int p = dfs(vv);
		if(!k) ret += p;
	}
	ret %= 2;
	v[ret].PB(a[nd]);
	return ret;
}

map<int, int> mp, mp1;

int main () {
#ifdef kfoozminus
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
#endif
	int n, i, x, _nim;
	scanf("%d", &n);
	for(i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
	}
	for(i = 2; i <= n; i ++) {
		scanf("%d", &x);
		edge[x].PB(i);
	}
	dfs(1);
	vsort(v[1]);
	for(auto it : v[0]) {
		mp[ it ] ++;
	}
	for(i = 0; i < v[1].size(); i ++) {
		if(!i || (v[1][i] != v[1][i - 1])) mp1[ v[1][i] ] += mp[ v[1][i] ];
		mp1[ v[1][i] ] ++;
	}
	int nim = 0;
	for(auto it : v[1]) nim ^= it;
	ll ans = 0;
	if(nim) {
		for(auto it : v[1]) {
			_nim = nim ^ it;
			ans += mp[ _nim ];
		}
	}
	else {
		for(map<int, int> :: iterator it = mp1.begin(); it != mp1.end(); it ++) {
			ll j = it -> S;
			ans += j * (j - 1) / 2;
		}
	}
	cout << ans << endl;
	/*int i, j;
	while(scanf("%d", &i) == 1) {
		while(scanf("%d", &j)) {
			if(!j) break;
			i ^= j;
		}
		cout << i << endl;
	}*/

//	timeStamp;
	return 0;
}


/*
ID: kfoozminus
TASK:
LANG: C++
*/

#include <bits/stdc++.h>
using namespace std;
//typedefs
/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <int, pii> piii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> pll;
const double PI = acos(-1);
*/
//typedefs
#define ll long long
#define ull unsigned long long
#define pii pair <int, int>
#define piii pair <int, pii>
#define vi vector <int>
#define vl vector <ll>
#define pll pair <ll, ll>
#define PI acos(-1)
//defines
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define mem(a, b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define SQR(a) ((a)*(a))
#define inf 100000000
#define mod 1000000007
#define mod1 1000000007
#define mod2 1000000009
#define b1 43
#define b2 41
#define EPS 1e-9
//define harmonic(n) 0.57721566490153286l+log(n)
#define nl puts("")
#define odd(n) ((n)&1)
#define even(n) (!((n)&1))
#define vsort(v) sort(v.begin(), v.end())
#define lc (node<<1)
#define rc ((node<<1)|1)
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
//loop
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
//input
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sd(a) scanf("%lf", &a)
#define sc(a) scanf("%c", &a)
#define sst(a) scanf("%s", a)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
//debug
#ifdef kfoozminus

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
	os << "{";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << *it;
	}
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin()) os << ", ";
		os << *it;
	}
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
	}
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
	for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }

#else
#define dbg(args...)
#endif
/*
ll add(ll a, ll b) {
	ll ret = a+b;
	if(ret >= mod) ret -= mod;
	return ret;
}

ll subtract(ll a, ll b) {
	ll ret = a-b;
	if(ret < 0) ret += mod;
	return ret;
}

ll mult(ll a, ll b) {
	ll ret = a*b;
	if(ret >= mod) ret %= mod;
	return ret;
}

ll bigmod(ll a, ll b) {
	ll ret = 1;
	while(b) {
		if(b&1) ret = mult(ret, a);
		b >>= 1; a = mult(a, a);
	}
	return ret;
}
*/

//ll inverse(ll n) { return bigmod(n, mod-2); }

/*
#define PMX 1000000

int marked[PMX/64 + 2];
vi primes;

#define mark(x) marked[x >> 6] |= (1 << ((x & 63) >> 1))
#define check(x) (marked[x >> 6] & (1 << ((x & 63) >> 1)))

bool isPrime(int x)
{
	return (x > 1) && ((x == 2) || ((x & 1) && (!(check(x)))));
}

void seive(int n)
{
	int i, j;
	for(i = 3; i * i <= n; i += 2) if(!check(i)) for(j = i * i; j <= n; j += i << 1) mark(j);
	primes.PB(2);
	for(i = 3; i <= n; i += 2) if(isPrime(i)) primes.PB(i);
}
*/

//Direction Array
//int fx[]={1, -1, 0, 0}; int fy[]={0, 0, 1, -1};
//int fx[]={0, 0, 1, -1, -1, 1, -1, 1}; int fy[]={-1, 1, 0, 0, 1, 1, -1, -1};

//bit manipulation
/*
bool checkBit(int n, int i) { return (n&(1<<i)); }
int setBit(int n, int i) { return (n|(1<<i)); }
int resetBit(int n, int i) { return (n&(~(1<<i))); }
*/
//end of template

#define MX 100007

vector<int> v[3], edge[MX];
int a[MX];

int dfs(int nd)
{
	int ret = 1;
	for(int k = 0; k < edge[nd].size(); k ++) {
		int vv = edge[nd][k];
		int p = dfs(vv);
		if(!k) ret += p;
	}
	ret %= 2;
	v[ret].PB(a[nd]);
	return ret;
}

map<int, int> mp, mp1;

int main () {
#ifdef kfoozminus
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
#endif
	int n, i, x, _nim;
	scanf("%d", &n);
	for(i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
	}
	for(i = 2; i <= n; i ++) {
		scanf("%d", &x);
		edge[x].PB(i);
	}
	dfs(1);
	for(auto it : v[0]) mp[ it ] ++;
	for(auto it : v[1]) mp1[ it ] ++;
	int nim = 0;
	for(auto it : v[1]) nim ^= it;
	ll ans = 0;
	if(nim) {
		for(auto it : v[1]) {
			_nim = nim ^ it;
			ans += mp[ _nim ];
		}
	}
	else {
		for(map<int, int> :: iterator it = mp1.begin(); it != mp1.end(); it ++) {
			ll j = it -> S;
			ans += j * (j - 1) / 2;
		}
	}
	cout << ans << endl;
	/*int i, j;
	while(scanf("%d", &i) == 1) {
		while(scanf("%d", &j)) {
			if(!j) break;
			i ^= j;
		}
		cout << i << endl;
	}*/

//	timeStamp;
	return 0;
}


/*
ID: kfoozminus
TASK:
LANG: C++
*/

#include <bits/stdc++.h>
using namespace std;
//typedefs
/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <int, pii> piii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> pll;
const double PI = acos(-1);
*/
//typedefs
#define ll long long
#define ull unsigned long long
#define pii pair <int, int>
#define piii pair <int, pii>
#define vi vector <int>
#define vl vector <ll>
#define pll pair <ll, ll>
#define PI acos(-1)
//defines
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define mem(a, b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define SQR(a) ((a)*(a))
#define inf 100000000
#define mod 1000000007
#define mod1 1000000007
#define mod2 1000000009
#define b1 43
#define b2 41
#define EPS 1e-9
//define harmonic(n) 0.57721566490153286l+log(n)
#define nl puts("")
#define odd(n) ((n)&1)
#define even(n) (!((n)&1))
#define vsort(v) sort(v.begin(), v.end())
#define lc (node<<1)
#define rc ((node<<1)|1)
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
//loop
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
//input
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sd(a) scanf("%lf", &a)
#define sc(a) scanf("%c", &a)
#define sst(a) scanf("%s", a)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
//debug
#ifdef kfoozminus

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
	os << "{";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << *it;
	}
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin()) os << ", ";
		os << *it;
	}
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
	}
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
	for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }

#else
#define dbg(args...)
#endif
/*
ll add(ll a, ll b) {
	ll ret = a+b;
	if(ret >= mod) ret -= mod;
	return ret;
}

ll subtract(ll a, ll b) {
	ll ret = a-b;
	if(ret < 0) ret += mod;
	return ret;
}

ll mult(ll a, ll b) {
	ll ret = a*b;
	if(ret >= mod) ret %= mod;
	return ret;
}

ll bigmod(ll a, ll b) {
	ll ret = 1;
	while(b) {
		if(b&1) ret = mult(ret, a);
		b >>= 1; a = mult(a, a);
	}
	return ret;
}
*/

//ll inverse(ll n) { return bigmod(n, mod-2); }

/*
#define PMX 1000000

int marked[PMX/64 + 2];
vi primes;

#define mark(x) marked[x >> 6] |= (1 << ((x & 63) >> 1))
#define check(x) (marked[x >> 6] & (1 << ((x & 63) >> 1)))

bool isPrime(int x)
{
	return (x > 1) && ((x == 2) || ((x & 1) && (!(check(x)))));
}

void seive(int n)
{
	int i, j;
	for(i = 3; i * i <= n; i += 2) if(!check(i)) for(j = i * i; j <= n; j += i << 1) mark(j);
	primes.PB(2);
	for(i = 3; i <= n; i += 2) if(isPrime(i)) primes.PB(i);
}
*/

//Direction Array
//int fx[]={1, -1, 0, 0}; int fy[]={0, 0, 1, -1};
//int fx[]={0, 0, 1, -1, -1, 1, -1, 1}; int fy[]={-1, 1, 0, 0, 1, 1, -1, -1};

//bit manipulation
/*
bool checkBit(int n, int i) { return (n&(1<<i)); }
int setBit(int n, int i) { return (n|(1<<i)); }
int resetBit(int n, int i) { return (n&(~(1<<i))); }
*/
//end of template

#define MX 100007

vector<int> v[3], edge[MX];
int a[MX];

int dfs(int nd)
{
	int ret = 1;
	for(int k = 0; k < edge[nd].size(); k ++) {
		int vv = edge[nd][k];
		int p = dfs(vv);
		if(!k) ret += p;
	}
	ret %= 2;
	v[ret].PB(a[nd]);
	return ret;
}

map<int, int> mp, mp1;

int main () {
#ifdef kfoozminus
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
#endif
	int n, i, x, _nim;
	scanf("%d", &n);
	for(i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
	}
	for(i = 2; i <= n; i ++) {
		scanf("%d", &x);
		edge[x].PB(i);
	}
	dfs(1);
	vsort(v[1]);
	for(auto it : v[0]) mp[ it ] ++;
	for(auto it : v[0]) mp1[ it ] ++;
	int nim = 0;
	for(auto it : v[1]) nim ^= it;
	ll ans = 0;
	if(nim) {
		for(auto it : v[1]) {
			_nim = nim ^ it;
			ans += mp[ _nim ];
		}
	}
	else {
		for(map<int, int> :: iterator it = mp1.begin(); it != mp1.end(); it ++) {
			ll j = it -> S;
			ans += j * (j - 1) / 2;
		}
	}
	cout << ans << endl;
	/*int i, j;
	while(scanf("%d", &i) == 1) {
		while(scanf("%d", &j)) {
			if(!j) break;
			i ^= j;
		}
		cout << i << endl;
	}*/

//	timeStamp;
	return 0;
}


/*
ID: kfoozminus
TASK:
LANG: C++
*/

#include <bits/stdc++.h>
using namespace std;
//typedefs
/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <int, pii> piii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> pll;
const double PI = acos(-1);
*/
//typedefs
#define ll long long
#define ull unsigned long long
#define pii pair <int, int>
#define piii pair <int, pii>
#define vi vector <int>
#define vl vector <ll>
#define pll pair <ll, ll>
#define PI acos(-1)
//defines
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define mem(a, b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define SQR(a) ((a)*(a))
#define inf 100000000
#define mod 1000000007
#define mod1 1000000007
#define mod2 1000000009
#define b1 43
#define b2 41
#define EPS 1e-9
//define harmonic(n) 0.57721566490153286l+log(n)
#define nl puts("")
#define odd(n) ((n)&1)
#define even(n) (!((n)&1))
#define vsort(v) sort(v.begin(), v.end())
#define lc (node<<1)
#define rc ((node<<1)|1)
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
//loop
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
//input
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sd(a) scanf("%lf", &a)
#define sc(a) scanf("%c", &a)
#define sst(a) scanf("%s", a)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
//debug
#ifdef kfoozminus

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
	os << "{";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << *it;
	}
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin()) os << ", ";
		os << *it;
	}
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
	}
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
	for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }

#else
#define dbg(args...)
#endif
/*
ll add(ll a, ll b) {
	ll ret = a+b;
	if(ret >= mod) ret -= mod;
	return ret;
}

ll subtract(ll a, ll b) {
	ll ret = a-b;
	if(ret < 0) ret += mod;
	return ret;
}

ll mult(ll a, ll b) {
	ll ret = a*b;
	if(ret >= mod) ret %= mod;
	return ret;
}

ll bigmod(ll a, ll b) {
	ll ret = 1;
	while(b) {
		if(b&1) ret = mult(ret, a);
		b >>= 1; a = mult(a, a);
	}
	return ret;
}
*/

//ll inverse(ll n) { return bigmod(n, mod-2); }

/*
#define PMX 1000000

int marked[PMX/64 + 2];
vi primes;

#define mark(x) marked[x >> 6] |= (1 << ((x & 63) >> 1))
#define check(x) (marked[x >> 6] & (1 << ((x & 63) >> 1)))

bool isPrime(int x)
{
	return (x > 1) && ((x == 2) || ((x & 1) && (!(check(x)))));
}

void seive(int n)
{
	int i, j;
	for(i = 3; i * i <= n; i += 2) if(!check(i)) for(j = i * i; j <= n; j += i << 1) mark(j);
	primes.PB(2);
	for(i = 3; i <= n; i += 2) if(isPrime(i)) primes.PB(i);
}
*/

//Direction Array
//int fx[]={1, -1, 0, 0}; int fy[]={0, 0, 1, -1};
//int fx[]={0, 0, 1, -1, -1, 1, -1, 1}; int fy[]={-1, 1, 0, 0, 1, 1, -1, -1};

//bit manipulation
/*
bool checkBit(int n, int i) { return (n&(1<<i)); }
int setBit(int n, int i) { return (n|(1<<i)); }
int resetBit(int n, int i) { return (n&(~(1<<i))); }
*/
//end of template

#define MX 100007

vector<int> v[3], edge[MX];
int a[MX];

int dfs(int nd)
{
	int ret = 1;
	for(int k = 0; k < edge[nd].size(); k ++) {
		int vv = edge[nd][k];
		int p = dfs(vv);
		if(!k) ret += p;
	}
	ret %= 2;
	v[ret].PB(a[nd]);
	return ret;
}

map<int, int> mp, mp1;

int main () {
#ifdef kfoozminus
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
#endif
	int n, i, x, _nim;
	scanf("%d", &n);
	for(i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
	}
	for(i = 2; i <= n; i ++) {
		scanf("%d", &x);
		edge[x].PB(i);
	}
	dfs(1);
	for(auto it : v[0]) mp[ it ] ++;
	for(auto it : v[1]) mp1[ it ] ++;
	int nim = 0;
	for(auto it : v[1]) nim ^= it;
	ll ans = 0;
	if(nim) {
		for(auto it : v[1]) {
			_nim = nim ^ it;
			ans += mp[ _nim ];
		}
	}
	else {
		ll j = v[1].size();
		ans = j * (j - 1) / 2;
		j = v[0].size();
		ans += j * (j - 1) / 2;
		for(map<int, int> :: iterator it = mp1.begin(); it != mp1.end(); it ++) {
			j = it -> S;
			//ans += j * (j - 1) / 2;
			ans += j * mp[ it -> F];
		}
	}
	cout << ans << endl;
	/*int i, j;
	while(scanf("%d", &i) == 1) {
		while(scanf("%d", &j)) {
			if(!j) break;
			i ^= j;
		}
		cout << i << endl;
	}*/

//	timeStamp;
	return 0;
}


/*
ID: kfoozminus
TASK:
LANG: C++
*/

#include <bits/stdc++.h>
using namespace std;
//typedefs
/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <int, pii> piii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> pll;
const double PI = acos(-1);
*/
//typedefs
#define ll long long
#define ull unsigned long long
#define pii pair <int, int>
#define piii pair <int, pii>
#define vi vector <int>
#define vl vector <ll>
#define pll pair <ll, ll>
#define PI acos(-1)
//defines
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define mem(a, b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define SQR(a) ((a)*(a))
#define inf 100000000
#define mod 1000000007
#define mod1 1000000007
#define mod2 1000000009
#define b1 43
#define b2 41
#define EPS 1e-9
//define harmonic(n) 0.57721566490153286l+log(n)
#define nl puts("")
#define odd(n) ((n)&1)
#define even(n) (!((n)&1))
#define vsort(v) sort(v.begin(), v.end())
#define lc (node<<1)
#define rc ((node<<1)|1)
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
//loop
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
//input
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sd(a) scanf("%lf", &a)
#define sc(a) scanf("%c", &a)
#define sst(a) scanf("%s", a)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
//debug
#ifdef kfoozminus

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
	os << "{";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << *it;
	}
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin()) os << ", ";
		os << *it;
	}
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
	}
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
	for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }

#else
#define dbg(args...)
#endif
/*
ll add(ll a, ll b) {
	ll ret = a+b;
	if(ret >= mod) ret -= mod;
	return ret;
}

ll subtract(ll a, ll b) {
	ll ret = a-b;
	if(ret < 0) ret += mod;
	return ret;
}

ll mult(ll a, ll b) {
	ll ret = a*b;
	if(ret >= mod) ret %= mod;
	return ret;
}

ll bigmod(ll a, ll b) {
	ll ret = 1;
	while(b) {
		if(b&1) ret = mult(ret, a);
		b >>= 1; a = mult(a, a);
	}
	return ret;
}
*/

//ll inverse(ll n) { return bigmod(n, mod-2); }

/*
#define PMX 1000000

int marked[PMX/64 + 2];
vi primes;

#define mark(x) marked[x >> 6] |= (1 << ((x & 63) >> 1))
#define check(x) (marked[x >> 6] & (1 << ((x & 63) >> 1)))

bool isPrime(int x)
{
	return (x > 1) && ((x == 2) || ((x & 1) && (!(check(x)))));
}

void seive(int n)
{
	int i, j;
	for(i = 3; i * i <= n; i += 2) if(!check(i)) for(j = i * i; j <= n; j += i << 1) mark(j);
	primes.PB(2);
	for(i = 3; i <= n; i += 2) if(isPrime(i)) primes.PB(i);
}
*/

//Direction Array
//int fx[]={1, -1, 0, 0}; int fy[]={0, 0, 1, -1};
//int fx[]={0, 0, 1, -1, -1, 1, -1, 1}; int fy[]={-1, 1, 0, 0, 1, 1, -1, -1};

//bit manipulation
/*
bool checkBit(int n, int i) { return (n&(1<<i)); }
int setBit(int n, int i) { return (n|(1<<i)); }
int resetBit(int n, int i) { return (n&(~(1<<i))); }
*/
//end of template

#define MX 100007

vector<int> v[3], edge[MX];
int a[MX];

int dfs(int nd)
{
	int ret = 1;
	for(int k = 0; k < edge[nd].size(); k ++) {
		int vv = edge[nd][k];
		int p = dfs(vv);
		if(!k) ret += p;
	}
	ret %= 2;
	v[ret].PB(a[nd]);
	return ret;
}

map<int, int> mp, mp1;

int main () {
#ifdef kfoozminus
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
#endif
	int n, i, x, _nim;
	scanf("%d", &n);
	for(i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
	}
	for(i = 2; i <= n; i ++) {
		scanf("%d", &x);
		edge[x].PB(i);
	}
	dfs(1);
	vsort(v[1]);
	for(auto it : v[0]) {
		mp[ it ] ++;
	}
	for(i = 0; i < v[1].size(); i ++) {
		//if(!i || (v[1][i] != v[1][i - 1])) mp1[ v[1][i] ] += mp[ v[1][i] ];
		mp1[ v[1][i] ] ++;
	}
	int nim = 0;
	for(auto it : v[1]) nim ^= it;
	ll ans = 0;
	if(nim) {
		for(auto it : v[1]) {
			_nim = nim ^ it;
			ans += mp[ _nim ];
		}
	}
	else {
		for(map<int, int> :: iterator it = mp1.begin(); it != mp1.end(); it ++) {
			ll j = it -> S;
			ans += j * (j - 1) / 2;
			ans += j * mp[ it -> F];
		}
	}
	cout << ans << endl;
	/*int i, j;
	while(scanf("%d", &i) == 1) {
		while(scanf("%d", &j)) {
			if(!j) break;
			i ^= j;
		}
		cout << i << endl;
	}*/

//	timeStamp;
	return 0;
}


/*input
3
1 2 3
1 1
*/

#include<bits/stdc++.h>
using namespace std;
#define mx 100005
int apple[mx];
vector<int> edge[mx];
map<int, int> mp[2];
int l;
int odd = 0;
pair<int, int> dfs(int u, int p, int lev)
{
	if(lev) odd++;
	mp[lev][apple[u]]++;
	pair<int, int> ret(apple[u], 0);
	for(int v : edge[u]){
		if(v != p){
			auto x = dfs(v, u, (lev+1)&1);
			ret.first ^= x.second;
			ret.second ^= x.first;
		}
	}
	if(edge[u].size()==1) l = lev;
	// cout << u << " * " << ret.first << " " << ret.second << endl;
	return ret;
}

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i<=n; i++)
    	scanf("%d", &apple[i]);
    for(int i = 2; i<n+1; i++)
    {
    	int a;
    	scanf("%d", &a);
    	edge[a].push_back(i);
    	edge[i].push_back(a);
    }
    auto xx = dfs(1, -1, 1);
    int even = n - odd;
    int ans;
    if(l){
    	ans = xx.first;
    }
    else ans = xx.second;

    long long res = 0;
    if(ans){
    	for(int i = 1; i<=n; i++)
    		res += 0ll + mp[!l][ans^apple[i]];
    }
    else{
    	long long tt = odd;
    	res += (tt * (tt-1)) / 2;
    	tt = even;
    	res += (tt * (tt-1)) / 2;
    	for(int i = 1; i<=n; i++)
    		res += 0ll + mp[!l][apple[i]];
    }
    printf("%lld\n", res);

	return 0;
}


/*input
3
2 2 3
1 1
*/

#include<bits/stdc++.h>
using namespace std;
#define mx 100005
int apple[mx];
vector<int> edge[mx];
map<int, int> mp[2];
int l;
int level[mx];
int odd = 0;
pair<int, int> dfs(int u, int p, int lev)
{
	if(edge[u].size()==1) l = lev;
	if(lev) odd++;
	mp[lev][apple[u]]++;
	level[u] = lev;
	pair<int, int> ret(apple[u], 0);
	for(int v : edge[u]){
		if(v != p){
			auto x = dfs(v, u, (lev+1)&1);
			ret.first ^= x.second;
			ret.second ^= x.first;
		}
	}
	// cout << u << " * " << ret.first << " " << ret.second << endl;
	return ret;
}

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i<=n; i++)
    	scanf("%d", &apple[i]);
    for(int i = 2; i<n+1; i++)
    {
    	int a;
    	scanf("%d", &a);
    	edge[a].push_back(i);
    	edge[i].push_back(a);
    }
    auto xx = dfs(1, -1, 1);
    int even = n - odd;
    int ans;
    if(l){
    	ans = xx.first;
    }
    else ans = xx.second;

    long long res = 0;
    if(ans){
    	for(int i = 1; i<=n; i++)
    		if(level[i]==l) res += 0ll + mp[!l][ans^apple[i]];
    }
    else{
    	long long tt = odd;
    	res += (tt * (tt-1)) / 2;
    	tt = even;
    	res += (tt * (tt-1)) / 2;
    	for(int i = 1; i<=n; i++)
    		if(level[i]==l) res += 0ll + mp[!l][apple[i]];
    }
    printf("%lld\n", res);

	return 0;
}


/*input
3
2 2 3
1 1
*/

#include<bits/stdc++.h>
using namespace std;
#define mx 100005
int apple[mx];
vector<int> edge[mx];
map<int, int> mp[2];
int l;
int level[mx];
int odd = 0;
pair<int, int> dfs(int u, int p, int lev)
{
	if(lev) odd++;
	mp[lev][apple[u]]++;
	level[u] = lev;
	pair<int, int> ret(apple[u], 0);
	for(int v : edge[u]){
		if(v != p){
			auto x = dfs(v, u, (lev+1)&1);
			ret.first ^= x.second;
			ret.second ^= x.first;
		}
	}
	if(edge[u].size()==1) l = lev;
	// cout << u << " * " << ret.first << " " << ret.second << endl;
	return ret;
}

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i<=n; i++)
    	scanf("%d", &apple[i]);
    for(int i = 2; i<n+1; i++)
    {
    	int a;
    	scanf("%d", &a);
    	edge[a].push_back(i);
    	edge[i].push_back(a);
    }
    auto xx = dfs(1, -1, 1);
    int even = n - odd;
    int ans;
    if(l){
    	ans = xx.first;
    }
    else ans = xx.second;

    long long res = 0;
    if(ans){
    	for(int i = 1; i<=n; i++)
    		if(level[i]==l) res += 0ll + mp[!l][ans^apple[i]];
    }
    else{
    	long long tt = odd;
    	res += (tt * (tt-1)) / 2;
    	tt = even;
    	res += (tt * (tt-1)) / 2;
    	for(int i = 1; i<=n; i++)
    		if(level[i]==l) res += 0ll + mp[!l][apple[i]];
    }
    printf("%lld\n", res);

	return 0;
}


/*input
8
7 2 2 5 4 3 1 1
1 1 1 4 4 5 6
*/

#include<bits/stdc++.h>
using namespace std;
#define mx 100005
int apple[mx];
vector<int> edge[mx];
map<int, int> mp[2];
int l;
int odd = 0;
pair<int, int> dfs(int u, int p, int lev)
{
	if(lev) odd++;
	mp[lev][apple[u]]++;
	pair<int, int> ret(apple[u], 0);
	for(int v : edge[u]){
		if(v != p){
			auto x = dfs(v, u, (lev+1)&1);
			ret.first ^= x.second;
			ret.second ^= x.first;
		}
	}
	if(edge[u].size()==1) l = lev;
	return ret;
}

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i<=n; i++)
    	scanf("%d", &apple[i]);
    for(int i = 2; i<n+1; i++)
    {
    	int a;
    	scanf("%d", &a);
    	edge[a].push_back(i);
    	edge[i].push_back(a);
    }
    auto xx = dfs(1, -1, 1);
    int even = n - odd;
    int ans;
    if(l){
    	ans = xx.first;
    }
    else ans = xx.second;

    long long res = 0;
    if(ans){
    	for(int i = 1; i<=n; i++)
    		res += 0ll + mp[!l][ans^apple[i]];
    }
    else{
    	long long tt = l==1? odd : even;
    	res += (tt * (tt-1)) / 2;
    	for(int i = 1; i<=n; i++)
    		res += 0ll + mp[!l][apple[i]];
    }
    printf("%lld\n", res);

	return 0;
}


#include <bits/stdc++.h>
#define MAX 1000005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
vector <int> v[100005];
int arr[MAX];
int color[MAX];
int good[50000000],bad[50000000];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>arr[i];
	for(int i=2;i<=n;i++)
	{
		int x;
		cin>>x;
		v[x].pb(i);
	}
	queue<int> q;
	q.push(1);
	int last=0;
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(int i=0;i<v[x].size();i++)
		{
			color[v[x][i]]=1-color[x];
			q.push(v[x][i]);
		}
		if(v[x].size()==0)
		{
			last=color[x];
		}
	}
	ll ans=0,cntg=0,cntb=0;
	for(int i=1;i<=n;i++)
	{
		if(color[i]==last)
		{
			good[arr[i]]++;
			ans^=arr[i];
			cntg++;
		}
		else
		{
			bad[arr[i]]++;
			cntb++;
		}
	}
	ll prt=0;
	//cout<<good[0]<<" "<<good[1]<<" "<<good[2]<<endl;
	if(ans==0)
	{
		prt+=cntg*(cntg-1)/2+cntb*(cntb-1)/2;
		prt+=cntg*cntb;
		//nonsimilar
		// swap red and black

	}

//	cout<<ans<<endl;
	ll temp=0;
	for(int i=1;i<(1<<24);i++)
		temp+=good[i]*bad[ans^i];
	cout<<prt+temp<<endl;
}


#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
vector <int> v[100005];
int arr[MAX];
int color[MAX];
ll good[(1<<24)+5],bad[(1<<24)+5];
int main()
{
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++)
		cin>>arr[i];
	for(ll i=2;i<=n;i++)
	{
		ll x;
		cin>>x;
		v[x].pb(i);
	}
	queue<ll> q;
	q.push(1);
	ll last=0;
	while(!q.empty())
	{
		ll x=q.front();
		q.pop();
		for(ll i=0;i<v[x].size();i++)
		{
			color[v[x][i]]=1-color[x];
			q.push(v[x][i]);
		}
		if(v[x].size()==0)
		{
			last=color[x];
		}
	}
	ll ans=0,cntg=0,cntb=0;
	for(ll i=1;i<=n;i++)
	{
		if(color[i]==last)
		{
			good[arr[i]]++;
			ans^=arr[i];
			cntg++;
		}
		else
		{
			bad[arr[i]]++;
			cntb++;
		}
	}
	ll prt=0;
	//cout<<good[0]<<" "<<good[1]<<" "<<good[2]<<endl;
	if(ans==0)
	{
		prt+=cntg*(cntg-1)/2+cntb*(cntb-1)/2;
		//nonsimilar
		// swap red and black

	}

//	cout<<ans<<endl;

	ll temp=0;
	for(ll i=1;i<(1<<24);i++)
		temp+=good[i]*1LL*bad[ans^i];
	cout<<prt+temp<<endl;
}


#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
vector <ll> v[100005];
ll arr[MAX];
ll color[MAX];
ll good[20000000],bad[20000000];
ll main()
{
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++)
		cin>>arr[i];
	for(ll i=2;i<=n;i++)
	{
		ll x;
		cin>>x;
		v[x].pb(i);
	}
	queue<ll> q;
	q.push(1);
	ll last=0;
	while(!q.empty())
	{
		ll x=q.front();
		q.pop();
		for(ll i=0;i<v[x].size();i++)
		{
			color[v[x][i]]=1-color[x];
			q.push(v[x][i]);
		}
		if(v[x].size()==0)
		{
			last=color[x];
		}
	}
	ll ans=0,cntg=0,cntb=0;
	for(ll i=1;i<=n;i++)
	{
		if(color[i]==last)
		{
			good[arr[i]]++;
			ans^=arr[i];
			cntg++;
		}
		else
		{
			bad[arr[i]]++;
			cntb++;
		}
	}
	ll prt=0;
	//cout<<good[0]<<" "<<good[1]<<" "<<good[2]<<endl;
	if(ans==0)
	{
		prt+=cntg*(cntg-1)/2+cntb*(cntb-1)/2;
		//nonsimilar
		// swap red and black

	}

//	cout<<ans<<endl;

	ll temp=0;
	for(ll i=1;i<(1<<24);i++)
		temp+=good[i]*bad[ans^i];
	cout<<prt+temp<<endl;
}


#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
vector <int> v[100005];
int arr[MAX];
int color[MAX];
int good[20000000],bad[20000000];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>arr[i];
	for(int i=2;i<=n;i++)
	{
		int x;
		cin>>x;
		v[x].pb(i);
	}
	queue<int> q;
	q.push(1);
	int last=0;
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(int i=0;i<v[x].size();i++)
		{
			color[v[x][i]]=1-color[x];
			q.push(v[x][i]);
		}
		if(v[x].size()==0)
		{
			last=color[x];
		}
	}
	ll ans=0,cntg=0,cntb=0;
	for(int i=1;i<=n;i++)
	{
		if(color[i]==last)
		{
			good[arr[i]]++;
			ans^=arr[i];
			cntg++;
		}
		else
		{
			bad[arr[i]]++;
			cntb++;
		}
	}
	ll prt=0;
	//cout<<good[0]<<" "<<good[1]<<" "<<good[2]<<endl;
	if(ans==0)
	{
		prt+=cntg*(cntg-1)/2+cntb*(cntb-1)/2;
		//nonsimilar
		// swap red and black

	}

//	cout<<ans<<endl;

	ll temp=0;
	for(int i=1;i<(1<<24);i++)
		temp+=good[i]*bad[ans^i];
	cout<<prt+temp<<endl;
}


#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
vector <int> v[100005];
int arr[MAX];
int color[MAX];
int good[20000000],bad[20000000];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>arr[i];
	for(int i=2;i<=n;i++)
	{
		int x;
		cin>>x;
		v[x].pb(i);
	}
	queue<int> q;
	q.push(1);
	int last=0;
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(int i=0;i<v[x].size();i++)
		{
			color[v[x][i]]=1-color[x];
			q.push(v[x][i]);
		}
		if(v[x].size()==0)
		{
			last=color[x];
		}
	}
	ll ans=0,cntg=0,cntb=0;
	for(int i=1;i<=n;i++)
	{
		if(color[i]==last)
		{
			good[arr[i]]++;
			ans^=arr[i];
			cntg++;
		}
		else
		{
			bad[arr[i]]++;
			cntb++;
		}
	}
	ll prt=0;
	//cout<<good[0]<<" "<<good[1]<<" "<<good[2]<<endl;
	if(ans==0)
	{
		prt+=cntg*(cntg-1)/2+cntb*(cntb-1)/2;
		prt+=cntg*cntb;
		//nonsimilar
		// swap red and black

	}

//	cout<<ans<<endl;
	ll temp=0;
	for(int i=1;i<(1<<24);i++)
		temp+=good[i]*bad[ans^i];
	cout<<prt+temp<<endl;
}


#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
vector <ll> v[100005];
ll arr[MAX];
int color[MAX];
int good[(1<<24)+5],bad[(1<<24)+5];
int main()
{
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++)
		cin>>arr[i];
	for(ll i=2;i<=n;i++)
	{
		ll x;
		cin>>x;
		v[x].pb(i);
	}
	queue<ll> q;
	q.push(1);
	ll last=0;
	while(!q.empty())
	{
		ll x=q.front();
		q.pop();
		for(ll i=0;i<v[x].size();i++)
		{
			color[v[x][i]]=1-color[x];
			q.push(v[x][i]);
		}
		if(v[x].size()==0)
		{
			last=color[x];
		}
	}
	ll ans=0,cntg=0,cntb=0;
	for(ll i=1;i<=n;i++)
	{
		if(color[i]==last)
		{
			good[arr[i]]++;
			ans^=arr[i];
			cntg++;
		}
		else
		{
			bad[arr[i]]++;
			cntb++;
		}
	}
	ll prt=0;
	//cout<<good[0]<<" "<<good[1]<<" "<<good[2]<<endl;
	if(ans==0)
	{
		prt+=cntg*(cntg-1)/2+cntb*(cntb-1)/2;
		//nonsimilar
		// swap red and black

	}

//	cout<<ans<<endl;

	ll temp=0;
	for(ll i=1;i<(1<<24);i++)
		temp+=good[i]*1LL*bad[ans^i];
	cout<<prt+temp<<endl;
}