(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #318464

#TimeUsernameProblemLanguageResultExecution timeMemory
318464Haruto810198Paprike (COI18_paprike)C++17
100 / 100
80 ms22756 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define vi vector<int> #define pii pair<int,int> #define si set<int> #define mii map<int,int> #define F first #define S second #define pb push_back #define pf push_front #define eb emplace_back #define ef emplace_front #define pob pop_back #define pof pop_front const int INF=2147483647; const int MOD=1000000007; const int mod=998244353; const double eps=1e-12; int n,k; int val[100001]; vi edge[100001]; vi subt[100001]; int sum[100001]; int res; void dfs(int v,int prev){ sum[v]=val[v]; for(int i=0;i<edge[v].size();i++){ if( edge[v][i] != prev ){ dfs( edge[v][i] , v ); sum[v]+=sum[ edge[v][i] ]; subt[v].pb( sum[ edge[v][i] ] ); } } sort(subt[v].begin(),subt[v].end()); reverse(subt[v].begin(),subt[v].end()); int ptr=0; while( sum[v] > k ){ sum[v]-=subt[v][ptr]; ptr++; res++; } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int v1,v2; cin>>n>>k; for(int i=0;i<n;i++){ cin>>val[i]; } for(int i=0;i<n-1;i++){ cin>>v1>>v2; v1--; v2--; edge[v1].pb(v2); edge[v2].pb(v1); } dfs(0,-1); cout<<res<<endl; return 0; }

Compilation message (stderr)

paprike.cpp: In function 'void dfs(long long int, long long int)':
paprike.cpp:39:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int i=0;i<edge[v].size();i++){
      |                 ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...