This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;
int n, d, dp[100][100];
void solve(){
cin >> n >> d;
for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) dp[i][j] = MOD;
for(int i = 0; i < n; ++i) dp[i][i] = 0;
for(int i = 0; i < n-1; ++i){
int u, v; cin >> u;
v = i + 1;
dp[u][v] = dp[v][u] = 1;
}
for(int k = 0; k < n; ++k){
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}
}
}
int ans = 0;
for(int mask = 0; mask < (1<<n); ++mask){
vector<int> v;
for(int i =0 ; i < n; ++i) if((1<<i)&mask) v.pb(i);
int s = v.size();
bool ok = 1;
for(int i = 0; i < s; ++i){
for(int j = i + 1; j < s; ++j){
int a = v[i], b = v[j];
if(dp[a][b] < d){
ok = 0;
}
}
}
if(ok) ans = max(ans, int(__builtin_popcount(mask)));
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
cout << '\n';
}
return 0;
}
Compilation message (stderr)
catinatree.cpp: In function 'int main()':
catinatree.cpp:61:16: warning: unused variable 'aa' [-Wunused-variable]
61 | int T = 1, aa;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |