Submission #388014

# Submission time Handle Problem Language Result Execution time Memory
388014 2021-04-09T18:12:19 Z b00n0rp Biochips (IZhO12_biochips) C++17
100 / 100
295 ms 399256 KB
/*
not my code. checking to submit whether the site is even working
*/
#include<bits/stdc++.h>
using namespace std;
 
int val[200001], m, t;
vector<int> g[200001];
int dp[200001][501], par[200001];
 
void dfs(int c)
{
    par[c] = t;
    for(int e : g[c]) dfs(e);
    for(int i=1;i<=m;i++)
        dp[t+1][i] = max(dp[t][i],dp[par[c]][i-1]+val[c]);
    t++;
}
 
int main()
{
    int n, r;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        int p;
        scanf("%d%d",&p,val+i);
        if(!p) r = i;
        else g[p].push_back(i);
    }
    for(int i=1;i<=m;i++) dp[0][i] = -1e9;
    dfs(r);
    printf("%d\n",dp[n][m]);
}
 

Compilation message

biochips.cpp: In function 'int main()':
biochips.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
biochips.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |         scanf("%d%d",&p,val+i);
      |         ~~~~~^~~~~~~~~~~~~~~~~
biochips.cpp:32:8: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |     dfs(r);
      |     ~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 5168 KB Output is correct
4 Correct 14 ms 22692 KB Output is correct
5 Correct 14 ms 24812 KB Output is correct
6 Correct 14 ms 24880 KB Output is correct
7 Correct 219 ms 297848 KB Output is correct
8 Correct 210 ms 297964 KB Output is correct
9 Correct 248 ms 361792 KB Output is correct
10 Correct 295 ms 399256 KB Output is correct