Submission #843225

# Submission time Handle Problem Language Result Execution time Memory
843225 2023-09-03T19:38:55 Z dungz Biochips (IZhO12_biochips) C++17
0 / 100
16 ms 13404 KB
//dau tuyen
//dau tuyen
//dau tuyen
#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define task "task"
#define task "task"
#define prll pair<ll,ll>
#define pb push_back
#define ld long double
const ll MIN=-1e18,MAX=1e18,MOD=1e9+7;
vector<int> a[200005];
int in[200005],out[200005];
int d=0;
int f[200005][505];
int val[200005];
void dfs(int u,int par)
{
    in[++d]=u;
    for(auto i:a[u])
    {
        if(i!=par)
        {
            dfs(i,u);
        }
    }
    out[u]=d;
}
int main(){
    #ifndef ONLINE_JUDGE
           freopen (task".inp", "r", stdin);
           freopen (task".out", "w", stdout);
    #endif
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        a[x].push_back(i);
//        cout<<x<<" "<<i<<endl;
        val[i]=y;

    }
    dfs(0,-1);
    for(int i=1;i<=d+1;i++) for(int j=1;j<=m;j++) f[i][j]=-2e9;
//    for(int i=1;i<=d;i++) cout<<in[i]<<" ";
//    cout<<endl;
    for(int i=d;i>=2;i--)
    {
        for(int j=1;j<=m;j++)
        {
            f[i][j]=max(val[in[i]]+f[out[in[i]]+1][j-1],f[i+1][j]);
//            ans=max(ans,f[i][j]);
        }
    }
    cout<<f[2][m];
}
/*
o(n*m^2) done

*/

Compilation message

biochips.cpp: In function 'int main()':
biochips.cpp:36:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |            freopen (task".inp", "r", stdin);
      |            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
biochips.cpp:37:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |            freopen (task".out", "w", stdout);
      |            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 13404 KB Execution killed with signal 11
2 Runtime error 16 ms 13400 KB Execution killed with signal 11
3 Runtime error 14 ms 13148 KB Execution killed with signal 11
4 Runtime error 14 ms 13148 KB Execution killed with signal 11
5 Runtime error 14 ms 13136 KB Execution killed with signal 11
6 Runtime error 14 ms 13148 KB Execution killed with signal 11
7 Runtime error 14 ms 13148 KB Execution killed with signal 11
8 Runtime error 15 ms 13156 KB Execution killed with signal 11
9 Runtime error 14 ms 13148 KB Execution killed with signal 11
10 Runtime error 14 ms 13148 KB Execution killed with signal 11