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

#TimeUsernameProblemLanguageResultExecution timeMemory
168554theStaticMindPaprike (COI18_paprike)C++14
100 / 100
76 ms19604 KiB
#include<bits/stdc++.h> #define mp make_pair #define pb push_back #define ii pair<int,int> #define all(x) (x).begin(),(x).end() #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 #define int long long int using namespace std; vector<int>adj[100005]; vector<int>val(100005,0); int n,k; int ans=0; int dfs(int x,int pre){ int sum=val[x]; priority_queue<int,vector<int>,greater<int>>Q; for(int i=0;i<adj[x].size();i++){ int y=adj[x][i]; if(y==pre)continue; Q.push(dfs(y,x)); } ans+=Q.size(); while(!Q.empty()&&sum+Q.top()<=k){ sum+=Q.top(); Q.pop(); ans--; } return sum; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("q.gir","r",stdin); // freopen("q.cik","w",stdout); cin>>n>>k; for(int i=1;i<=n;i++)cin>>val[i]; for(int i=0;i<n-1;i++){ int x,y; cin>>x>>y; adj[x].pb(y); adj[y].pb(x); } dfs(1,0); cout<<ans; }

Compilation message (stderr)

paprike.cpp: In function 'long long int dfs(long long int, long long int)':
paprike.cpp:18:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i=0;i<adj[x].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...