Submission #302571

# Submission time Handle Problem Language Result Execution time Memory
302571 2020-09-18T19:31:27 Z milisav Biochips (IZhO12_biochips) C++14
0 / 100
4 ms 5120 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define maxn 200010
#define maxm 510
using namespace std;
int n,m;
int rt;
int p[maxn];
int x[maxn];
vector<int> ch[maxn];
int a[maxn];
int s[maxn];
int dp[maxn][maxm];
int id=0;
int tot=0;
void dfs(int u) {
    int cid=id++;
    a[cid]=x[u];
    tot++;
    for(int i=0;i<ch[u].size();i++) {
        dfs(ch[u][i]);
    }
    s[cid]=id;
}
int main() {
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++) {
        scanf("%d %d",&p[i],&x[i]);
        if(p[i]==0) rt=i;
        else ch[p[i]].push_back(i);
	}
	dfs(rt);
	for(int j=1;j<=m;j++) dp[0][j]=-1e9;
	for(int i=0;i<n;i++) {
        for(int j=0;j<=m;j++) dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
        for(int j=0;j<=m-1;j++) dp[s[i]][j+1]=max(dp[s[i]][j+1],dp[i][j]+a[i]);
	}
    printf("%d",dp[n][m]);
	return 0;
}

Compilation message

biochips.cpp: In function 'void dfs(int)':
biochips.cpp:20:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i=0;i<ch[u].size();i++) {
      |                 ~^~~~~~~~~~~~~
biochips.cpp: In function 'int main()':
biochips.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |  scanf("%d %d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~~
biochips.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         scanf("%d %d",&p[i],&x[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Incorrect 4 ms 5120 KB Output isn't correct
3 Halted 0 ms 0 KB -