제출 #571525

#제출 시각아이디문제언어결과실행 시간메모리
571525tekiPaprike (COI18_paprike)C++11
13 / 100
55 ms15276 KiB
#include <bits/stdc++.h> typedef long long ll; #define pb push_back #define MS(x,y) memset((x),(y),sizeof((x))) #define MN 1000000001 using namespace std; const int nsize = 100001; int n,m,q; int parent[nsize]; int sajz[nsize]; vector<int> pat[nsize]; bool vis[nsize]; int vred[nsize]; int dfsConst(int pos, int parnt) { if (vis[pos]) return 0; vis[pos] = true; parent[pos] = parnt; for (auto it:pat[pos]) { sajz[pos] += dfsConst(it,pos); } return sajz[pos]; } bool custComp(int a, int b) { if (sajz[a] == sajz[b]) return a < b; return sajz[a] < sajz[b]; } int res = 0; int dfs(int pos, int zbir) { for (auto it:pat[pos]) { if (it == parent[pos]) continue; if (zbir+vred[it] > q) { dfs(it,vred[it]); res++; } else { zbir = dfs(it,zbir+vred[it]); } } return zbir; } int main() { #if LOCAL_DEBUG fstream cin("in.txt"); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>q; m = n-1; for (int i = 0; i<n; i++) cin>>vred[i]; for (int i = 0; i<m; i++) { int a,b; cin>>a>>b; a--; b--; pat[a].pb(b); pat[b].pb(a); } MS(vis,0); for (int i = 0; i<n; i++) sajz[i] = vred[i]; dfsConst(0,0); for (int i = 0; i<n; i++) sort(pat[i].begin(),pat[i].end(),custComp); dfs(0,vred[0]); cout<<res<<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...