(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 #640569

#TimeUsernameProblemLanguageResultExecution timeMemory
640569uyluluPaprike (COI18_paprike)C++14
100 / 100
53 ms18272 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ld long double #define endl "\n" const int N = 1e5; int n,k; int num[N + 1],mn[N + 1]; vector<int> adj[N + 1]; int res = 0; void dfs(int s,int pa) { mn[s] = num[s]; vector<int> asd; for(auto u : adj[s]) { if(u == pa) continue; dfs(u,s); asd.push_back(mn[u]); } sort(asd.begin(),asd.end()); for(int i = 0;i < asd.size();i++) { if(mn[s] + asd[i] > k) { res += ((int)asd.size() - i); break; } mn[s] += asd[i]; } } signed main() { // freopen("in.txt","r",stdin); // freopen("some.txt","w",stdout); ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>n>>k; for(int i = 1;i <= n;i++) cin>>num[i]; for(int i = 0;i < n - 1;i++) { int x,y; cin>>x>>y; adj[x].push_back(y); adj[y].push_back(x); } dfs(1,-1); cout<<res<<endl; }

Compilation message (stderr)

paprike.cpp: In function 'void dfs(long long int, long long int)':
paprike.cpp:25: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]
   25 |  for(int i = 0;i < asd.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...