이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> point;
const int MAXN = 1e5 + 5;
int n, k, cost[MAXN], sol;
vector <int> E[MAXN];
void dfs(int x, int p = -1){
vector <int> tmp;
for(auto e : E[x]){
if(e == p) continue;
dfs(e, x);
tmp.pb(cost[e]);
}
sort(tmp.begin(), tmp.end());
for(auto it : tmp)
if(cost[x] + it > k)
sol ++;
else
cost[x] += it;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
REP(i, n)
cin >> cost[i];
REP(i, n - 1){
int a, b; cin >> a >> b; a --; b --;
E[a].pb(b); E[b].pb(a);
}
dfs(0);
cout << sol << "\n";
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |