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

#TimeUsernameProblemLanguageResultExecution timeMemory
113096IVIosabPaprike (COI18_paprike)C++17
100 / 100
81 ms18040 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define f first #define s second int n,m; int ar[100005]; vector<vector<int>> adj(100005); int res=0; int vis[100005]; int dfs(int cur){ vis[cur]=1; vector<int> v; for(int i=0;i<adj[cur].size();i++){ if(!vis[adj[cur][i]]) { v.push_back(dfs(adj[cur][i])); } } sort(v.begin(),v.end()); int ret=ar[cur]; for(int i=0;i<v.size();i++){ if(v[i]+ret>m){ res++; } else{ ret+=v[i]; } } return ret; } int main() { //freopen("sample-8.in", "r", stdin); //freopen("output8.txt", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=0;i<n;i++){ cin>>ar[i]; } for(int i=0;i<n-1;i++){ int a,b; cin>>a>>b; a--; b--; adj[a].push_back(b); adj[b].push_back(a); } dfs(0); cout<<res<<endl; return 0; }

Compilation message (stderr)

paprike.cpp: In function 'int dfs(int)':
paprike.cpp:16:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<adj[cur].size();i++){
                 ~^~~~~~~~~~~~~~~~
paprike.cpp:23:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     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...