Submission #1035277

#TimeUsernameProblemLanguageResultExecution timeMemory
1035277MarwenElarbiChase (CEOI17_chase)C++17
0 / 100
4062 ms124756 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...