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

#TimeUsernameProblemLanguageResultExecution timeMemory
43905mraronPaprike (COI18_paprike)C++14
100 / 100
117 ms19456 KiB
//Noszály Áron 10o Debreceni Fazekas Mihály Gimnázium #include<iostream> #include<vector> #include<map> #include<set> #include<cassert> #include<cassert> #include<unordered_map> #include<unordered_set> #include<functional> #include<queue> #include<stack> #include<cstring> #include<algorithm> #include<cmath> #include<sstream> #include<iomanip> #include<cstdio> #include<cstdlib> #include<numeric> using namespace std; #define all(x) (x).begin(), (x).end() #define pb push_back #define xx first #define yy second #define sz(x) (int)(x).size() #define FORN(i, n) for(int i=0;i<(n);i++) #define gc getchar #define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define rep(i, l, r) for ((i) = (l); (i) < (r); (i)++) typedef long long ll; typedef unsigned long long ull; typedef long double ld; const double PI=acos(-1); template<typename T> T getint() { T val=0; char c; bool neg=false; while((c=gc()) && !(c>='0' && c<='9')) { neg|=c=='-'; } do { val=(val*10)+c-'0'; } while((c=gc()) && (c>='0' && c<='9')); return val*(neg?-1:1); } #define int ll const int maxn=100001; int n, k; int cost[maxn]; vector<int> adj[maxn]; pair<int,int> dfs(int x, int par=-1) { int child=0; int sum=cost[x]; int ans=0; priority_queue<int> pq; for(auto i:adj[x]) { if(par==i) continue ; child++; pair<int,int> akt=dfs(i, x); pq.push(akt.yy); ans+=akt.xx; sum+=akt.yy; } while(!pq.empty() && sum>k) { sum-=pq.top();ans++; pq.pop(); } return {ans, sum}; } main() { IO; cin>>n>>k; for(int i=1;i<=n;++i) { cin>>cost[i]; } for(int i=1;i<n;++i) { int a,b;cin>>a>>b; adj[a].pb(b); adj[b].pb(a); } cout<<dfs(1).xx<<"\n"; return 0; }

Compilation message (stderr)

paprike.cpp:90:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...