Submission #465436

#TimeUsernameProblemLanguageResultExecution timeMemory
465436osmanallazovPaprike (COI18_paprike)C++14
0 / 100
124 ms17488 KiB
#include <bits/stdc++.h> using namespace std; long long n,k; long long ans=0; long long val[100005]; long long a[100005]; long long b[100005]; vector<long long>qraf[100005]; int dfs(long long x, long long par){ vector<long long>v; for(int i=0;i<(qraf[x]).size();i++){ long long child=qraf[x][i]; if(child==par) continue; v.push_back(dfs(child,x)); } sort(v.begin(),v.end()); long long sum=0; for(int i=0;i<v.size();i++) sum += v[i]; for(int i=v.size()-1;i>=0;i--){ if(sum>k){ sum-=v[i]; ans++; } else{break;} } return sum; } int main (){ cin>>n>>k; for(int i=0; i<n; i++){ cin>>val[i]; } for(int i=0; i<n-1; i++){ cin>>a[i]>>b[i]; qraf[a[i]].push_back(b[i]); qraf[b[i]].push_back(a[i]); } dfs(1,0); cout<<ans; }

Compilation message (stderr)

paprike.cpp: In function 'int dfs(long long int, long long int)':
paprike.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0;i<(qraf[x]).size();i++){
      |                 ~^~~~~~~~~~~~~~~~~
paprike.cpp:19:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i=0;i<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...