| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 883401 | dimashhh | Cat in a tree (BOI17_catinatree) | C++17 | 1 ms | 344 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1501,MOD = 1e9 + 7;
int n,d,dp[N][N];
vector<int> g[N];
void dfs(int v,int pr = -1){
dp[v][0] = 1;
for(int to:g[v]){
if(to == pr) continue;
dfs(to,v);
dp[v][0] += dp[to][d - 1];
}
for(int dep = 1;dep <= n;dep++){
if(d - dep - 1 < 0) continue;
int mx = -1e9;
for(int to:g[v]){
if(to == pr) continue;
dp[v][dep] += dp[to][d - dep - 1];
mx = max(mx,dp[to][dep - 1] - dp[to][d - dep -1 ]);
}
dp[v][dep] += mx;
}
for(int i = n;i >= 1;i--){
dp[v][i] = max(dp[v][i + 1],dp[v][i]);
}
}
void test(){
cin >> n >> d;
for(int i = 1;i < n;i++){
int x;
cin >> x;
++x;
g[x].push_back(i);
}
dfs(1);
cout << dp[1][0];
}
main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int T = 1;
// cin >> T;
while(T--)
test();
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
