#include<bits/stdc++.h>

using namespace std;
 
#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  1e5+5;
const ll   mod   =  998244353;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll n, k, a[55][55];
ll p[55], sz[55], f[55];

void make(ll n){
	for(int i = 1; i <= n; i++){
		p[i] = i;
		sz[i] = 1;
	}
}

int find(ll x){
	return (p[x] == x)? x: p[x] = find(p[x]);
}

void merge(ll x, ll y){
	ll a = find(x);
	ll b = find(y);
	if(a != b){
		if(sz[a] >= sz[b]) swap(a,b);
		p[a] = b;
		sz[b] += sz[a];
	}
}

bool can(int x, int y, int f){
	if(f == 1){
		for(int i = 1; i <= n; i++){
			if(a[i][x] + a[i][y] > k) return 0;
		}
	} else {
		for(int i = 1; i <= n; i++){
			if(a[x][i] + a[y][i] > k) return 0;
		}
	}
	return 1;
}

void solve(){
	f[0] = 1;
	for(int i = 1; i < 55; i++) f[i] = f[i - 1] * i % mod;
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			cin >> a[i][j];
		}
	}
	ll ans = 1;
	make(n);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(can(i, j, 0)) merge(i, j);
		}
	}
	for(int i = 1; i <= n; i++){
		if(find(i) == i){
			ans = ans * f[sz[i]] % mod;
		}
	}
	make(n);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(can(i, j, 1)) merge(i, j);
		}
	}
	for(int i = 1; i <= n; i++){
		if(find(i) == i){
			ans = ans * f[sz[i]] % mod;
		}
	}
	deb1(ans)
}

int main(){
	GODSPEED;
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; i++){
		solve();
	}
}
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = b; i >= a; --i)
#define all(x) x.begin(), x.end()
 
using ll = long long;
using namespace std;

const int N = 1 << 20;

int n, dp[N], sz[N];
vector<int> g[N];

void dfs(int v) {
	sz[v] = 1;
	vector<int> q;
	vector<pair<int, int>> h;
	for (auto u : g[v]) {
		dfs(u);
		sz[v] += sz[u];
		if (sz[u] % 2 == 0) {
			int he = sz[u] - dp[u];
			int im = dp[u];
			if (im >= he) {
				dp[v] += im;
			}
			else {
				dp[v] += min(im, he);
				q.pb(he - im);
			}
		}
		else {
			h.pb({2 * dp[u] - sz[u], dp[u]});
		}
	}
	sort(all(q));
	sort(all(h));
	reverse(all(h));
	rep(i, 0, sz(h) - 1) {
		if (i % 2 == 0) dp[v] += h[i].se;
		if (i % 2 == 1) dp[v] += (h[i].fi - h[i].se) * -1;
	}
	if (sz(h) % 2 == 1)
		for (auto x : q)
			dp[v] += x;
}

int main() {
	scanf("%d", &n);
	rep(i, 2, n) {
		int p;
		scanf("%d", &p);
		g[p].pb(i);
	}
	dfs(1);
	printf("%d\n", n - dp[1]);
	return 0;
}
