| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 236404 | mahmoudbadawy | 바이오칩 (IZhO12_biochips) | C++17 | 695 ms | 402296 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
vector<int> adj[N];
int arr[N],dp[N][505];
int n,m;
void dfs(int node)
{
int tmp[505];
for(int u:adj[node])
{
dfs(u);
for(int i=0;i<=m;i++) tmp[i]=0;
for(int i=0;i<=m;i++)
{
if(i&&dp[node][i]==0) break;
for(int j=1;i+j<=m;j++)
{
if(dp[u][j]==0) break;
tmp[i+j]=max(tmp[i+j],dp[node][i]+dp[u][j]);
}
}
for(int i=0;i<=m;i++) dp[node][i]=max(dp[node][i],tmp[i]);
}
dp[node][1]=max(dp[node][1],arr[node]);
}
int main()
{
scanf("%d %d",&n,&m);
int root=-1;
for(int i=1;i<=n;i++)
{
int pa;
scanf("%d %d",&pa,&arr[i]);
if(pa) adj[pa].push_back(i);
else root=i;
}
dfs(root);
cout << dp[root][m] << endl;
/*for(int x=1;x<=n;x++)
{
for(int i=0;i<=m;i++)
cout << dp[x][i] << " ";
cout << endl;
}*/
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
