This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 20, M = (1<<20);
int n, d, nb[N], dp[M];
vector<int> adj[N];
void dfs(int u, int p, int t, int r) {
if (t >= d) return;
nb[r] ^= (1<<u);
for (int v:adj[u]) {
if (v == p) continue;
dfs(v, u, t+1, r);
}
}
void solve() {
cin >> n >> d;
for (int u = 1; u < n; u++) {
int p;
cin >> p;
adj[u].push_back(p);
adj[p].push_back(u);
}
for (int u = 0; u < n; u++) {
dfs(u, -1, 0, u);
}
dp[0] = 0;
for (int mask = 1; mask < (1<<n); mask++) {
int u = __builtin_ctz(mask);
dp[mask] = max(dp[mask^(1<<u)], dp[mask^(mask&nb[u])]+1);
}
cout << dp[(1<<n)-1] << endl;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |