| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1261071 | duyanhchupapi | Cat in a tree (BOI17_catinatree) | C++20 | 47 ms | 20040 KiB |
#include <bits/stdc++.h>
using namespace std; const int N = 200005;
int n, d, ans, f[N];
vector<int> g[N];
void dfs(int u,int p) {
f[u] = 0;
for(int v : g[u]){
if(v == p) continue;
dfs(v, u);
if(f[u] + f[v] + 1 >= d) ++ans, f[u] = min(f[u], f[v] + 1);
else f[u] = max(f[u], f[v] + 1);
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> d; ans = 1;
for(int i=1;i<n;++i) {
int x;cin >> x;
g[x].push_back(i);
g[i].push_back(x);
}
dfs(0, -1);
cout << ans;
return 0;
}| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
