# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
143018 | davitmarg | Cat in a tree (BOI17_catinatree) | C++17 | 59 ms | 28664 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
int n,d,dp[2000][2000],upd[2000][2000],sz[200005],ans=1;
vector<int> g[200005];
void dfs(int v)
{
sz[v]=1;
for(int i=0;i<g[v].size();i++)
{
int to=g[v][i];
dfs(to);
}
dp[v][0]=1;
for(int i=0;i<g[v].size();i++)
{
int to=g[v][i];
for(int k1=0;k1<=d && k1<=sz[v];k1++)
for(int k2=0;k2<=d && k2<=sz[to];k2++)
if(k1+k2+1>=d)
upd[v][min(k2+1,k1)]=max(upd[v][min(k2+1,k1)],dp[to][k2]+dp[v][k1]);
for(int k2=0;k2<=d && k2<=sz[to];k2++)
upd[v][k2+1]=max(dp[to][k2],upd[v][k2+1]);
sz[v]+=sz[to];
for(int k=d;k>=0;k--)
{
dp[v][k]=max(dp[v][k],upd[v][k]);
dp[v][k]=max(dp[v][k],dp[v][k+1]);
upd[v][k]=0;
}
}
// cout<<"! "<<v<<endl;
// for(int k=0;k<=d && k<=sz[v];k++)
// cout<<k<<" = "<<dp[v][k]<<"\n";
for(int k=0;k<=d;k++)
ans=max(ans,dp[v][k]);
}
int main()
{
cin>>n>>d;
for(int i=1;i<n;i++)
{
int p;
scanf("%d",&p);
g[p].PB(i);
}
dfs(0);
cout<<ans<<endl;
return 0;
}
/*
*/
컴파일 시 표준 에러 (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... |