Submission #1035277

# Submission time Handle Problem Language Result Execution time Memory
1035277 2024-07-26T08:37:26 Z MarwenElarbi Chase (CEOI17_chase) C++17
0 / 100
4000 ms 124756 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int nax=1e5+5;
const int MOD=1e9+9;
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int tab[nax];
long long sum[nax];
long long dp[nax][105];
vector<pair<int,ll>> adj[nax];
long long dfs(int x,int lvl,int p){
    if(dp[x][lvl]!=0) return dp[x][lvl];
    if(lvl==0) return 0;
    dp[x][lvl]=0;
    for(auto u:adj[x]){
        if(u.fi==p) continue;
        cout <<u.se<<endl;
        dp[x][lvl]=max(dp[x][lvl],u.se+dfs(u.fi,lvl-1,x));
        dp[x][lvl]=max(dp[x][lvl],dfs(u.fi,lvl,x));
    }
    return dp[x][lvl];
}
int main()
{
    optimise;
    int n,k;
    cin>>n>>k;
    for (int i = 0; i < n; ++i)
    {
        cin>>tab[i];
    }
    for (int i = 0; i < n-1; ++i)
    {
        int x,y;
        cin>>x>>y;
        x--;y--;
        sum[x]+=tab[y];
        sum[y]+=tab[x];
        adj[x].pb({y,0});
        adj[y].pb({x,0});
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < adj[i].size(); ++j)
        {
            adj[i][j].se=sum[adj[i][j].fi]-tab[i];
        }
    }
    cout <<max(dfs(0,k,-1),dfs(0,k-1,-1)+sum[0])<<endl;
}

Compilation message

chase.cpp: In function 'int main()':
chase.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int j = 0; j < adj[i].size(); ++j)
      |                         ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4062 ms 124756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -