# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
924889 | Faisal_Saqib | Cat in a tree (BOI17_catinatree) | C++17 | 0 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
const int N=1501;
vector<int> ma[N];
int dp[N][N];
int d;
int n;
void dfs(int x,int p=-1)
{
for(int y:ma[x])
if(y!=p)
dfs(y,x);
dp[x][0]=1;
for(int j=n;j>=1;j--)
{
dp[x][j]=0;
for(int c:ma[x])
dp[x][j]+=dp[c][j-1];
dp[x][j]=max(dp[x][j],dp[x][j+1]);
dp[x][j]=max(1,dp[x][j]);
}
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
cin>>n>>d;
for(int i=2;i<=n;i++)
{
int p;
cin>>p;
p++;
ma[p].push_back(i);
ma[i].push_back(p);
}
int ans=0;
dfs(1);
if(d>=n)
{
cout<<1<<endl;
}
else
{
cout<<dp[1][d]<<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... |