# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
967184 | mdobric | Paprike (COI18_paprike) | C++11 | 41 ms | 18816 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, a[maxn], b[maxn], p[maxn];
long long h[maxn], k;
int dp[maxn];
long long ostatak[maxn];
vector <int> v[maxn];
void dfs (int x){
for (int i = 0; i < v[x].size(); i++){
if (p[x] != v[x][i]){
p[v[x][i]] = x;
dfs(v[x][i]);
}
}
}
int solve (int x){
vector <long long> sve;
for (int i = 0; i < v[x].size(); i++){
if (p[x] != v[x][i]){
solve(v[x][i]);
dp[x] += dp[v[x][i]];
sve.push_back(ostatak[v[x][i]]);
}
}
sort(sve.begin(), sve.end());
long long tr = h[x];
for (int i = 0; i < sve.size(); i++){
if (tr + sve[i] <= k){
tr += sve[i];
}
else{
dp[x]++;
}
}
ostatak[x] = tr;
//cout << x << " : " << dp[x] << " " << ostatak[x] << endl;
//cout << sve.size() << endl << endl;
return dp[x];
}
int main (void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> k;
for (int i = 1; i <= n; i++){
cin >> h[i];
}
for (int i = 0; i < n - 1; i++){
cin >> a[i] >> b[i];
v[a[i]].push_back(b[i]);
v[b[i]].push_back(a[i]);
}
dfs(1);
cout << solve(1) << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |