제출 #386659

#제출 시각아이디문제언어결과실행 시간메모리
386659loctildorePaprike (COI18_paprike)C++14
100 / 100
70 ms17900 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define x first
#define y second
#define elif else if
#define endl '\n'
#define all(x) begin(x), end(x)
int n,k,x,y,total;
int spice[100069];
vector<int> gph[100069];
bool done[100069];
int dfs(int node){
  done[node]=true;
  vector<int> vct;
  for (int i:gph[node]) {
    if (!done[i]) {
      vct.push_back(dfs(i));
    }
  }
  int cur=spice[node];
  sort(all(vct));
  for (int i : vct) {
    if (cur+i<=k) {
      cur+=i;
    }
    else{
      total++;
    }
  }
  return cur;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin>>n>>k;
  for (int i = 0; i < n; i++) {
    cin>>spice[i];
  }
  for (int i = 0; i < n-1; i++) {
    cin>>x>>y;
    x--;y--;
    gph[x].push_back(y);
    gph[y].push_back(x);
  }
  dfs(0);
  cout<<total<<endl;
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...