Submission #1117629

#TimeUsernameProblemLanguageResultExecution timeMemory
1117629vjudge1Paprike (COI18_paprike)C++17
13 / 100
34 ms12168 KiB
#pragma GCC optimize("O3") #include<bits/stdc++.h> #define ll long long #define endl "\n" #define AI ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; vector<ll>val; vector<vector<ll>>edge; vector<ll>check; ll k,c=0; ll dfs(ll i) { check[i]=1; ll x=-1; ll y=-1; for(ll j:edge[i]) { if(!check[j]) { if(x==-1) x=dfs(j); else y=dfs(j); } } x=max(0LL,x); y=max(0LL,y); if(x+y+val[i]>k) { c++; if(min(x,y)+val[i]>k) { c++; return val[i]; } return min(x,y)+val[i]; } return x+y+val[i]; } int main() { AI //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); ll n,a,b,i; cin>>n>>k; val.resize(n+1); for(i=1;i<=n;i++) cin>>val[i]; edge.resize(n+1); check.resize(n+1,0); for(i=1;i<n;i++) { cin>>a>>b; edge[a].push_back(b); edge[b].push_back(a); } for(i=1;i<=n;i++) { if(!check[i]) dfs(i); } cout<<c<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...