이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |