Submission #519441

#TimeUsernameProblemLanguageResultExecution timeMemory
519441KiriLL1caCat in a tree (BOI17_catinatree)C++17
0 / 100
3 ms4940 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fr first #define sc second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back #define endl '\n' #define pw(x) (1ll << x) #define sz(x) (int)((x).size()) #define sqr(x) ((ll)x)*((ll)x) #define bcnt(X) __builtin_popcountll(X) #define vec vector #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx2,tune=native") using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair <int, int> pii; typedef pair <ll, ll> pll; auto rng = bind(uniform_int_distribution<int>(1, 1e9), mt19937(133751)); const int N = 2e5 + 10; int n, d; vector <int> g[N]; int ans = 1; void dfs (int v, int p, int keep) { if (!keep) ans++, keep = d; for (auto u : g[v]) { if (u != p) dfs(u, v, keep - 1); } } inline void solve () { cin >> n >> d; for (int i = 1; i < n; i++) { int p; cin >> p; g[i].pb(p); g[p].pb(i); } for (int i = 0; i < n; i++) { if (sz(g[i]) == 1) { dfs(i, -1, d); cout << ans; return; } } } signed main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...