Submission #1117639

#TimeUsernameProblemLanguageResultExecution timeMemory
1117639vjudge1Paprike (COI18_paprike)C++14
100 / 100
44 ms16844 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define pb push_back #define F first #define S second #define ll long long #define int ll #define pii pair<int, int> #define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define M_PI 3.14159265358979323846 #define all(v) v.begin(), v.end() #define pss pair<string, string> #define no cout<<"No"<<endl; #define yes cout<<"Yes"<<endl; #define imp cout<<-1<<endl; #define flu cout.flush(); #define Endl endl const int N = 100009; const int mod = 1e9+7; int n, k, ans=0, used[N], start=1; vector<int>spi; vector<int>a[N]; int dfs(int node){ used[node]=1; if(a[node].size()==1 and node!=start){ return spi[node-1]; } vector<int>child; for(int i : a[node]){ if(used[i]==0){ child.pb(dfs(i)); } } sort(all(child)); int own=spi[node-1], sz=child.size(); int en=sz; for(int i=0; i<sz; i++){ if(own+child[i]<=k){ own+=child[i]; } else{ en=i; break; } } //cout<<node<<" "<<sz<<" "<<en<<" "<<own<<endl; ans+=(sz-en); return own; } void solve(){ cin>>n>>k; for(int i=0; i<n; i++){ int x; cin>>x; spi.pb(x); } for(int i=0; i<n-1; i++){ int x, y; cin>>x>>y; a[x].pb(y); a[y].pb(x); } int q=0; for(int i=1; i<=n; i++){ if(a[i].size()>q){ q=a[i].size(); start=i; } } //cout<<start<<endl; int useless=dfs(start); cout<<ans<<endl; } signed main(){ io; int t=1; //cin>>t; while(t--){ solve(); } }

Compilation message (stderr)

paprike.cpp: In function 'void solve()':
paprike.cpp:71:23: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   71 |         if(a[i].size()>q){
      |            ~~~~~~~~~~~^~
paprike.cpp:77:9: warning: unused variable 'useless' [-Wunused-variable]
   77 |     int useless=dfs(start);
      |         ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...