# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
169466 | rzbt | Paprike (COI18_paprike) | C++14 | 121 ms | 23056 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <algorithm>
#include <vector>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 100005
typedef long long ll;
using namespace std;
int n,k,spice[MAXN];
int res=0;
vector<int> deca[MAXN],niz[MAXN];
int dfs(int t,int o){
for(auto x:niz[t]){
if(x==o)continue;
deca[t].pb(dfs(x,t));
}
sort(all(deca[t]));
int tz=spice[t];
for(auto x:deca[t]){
if(tz+x<=k)tz+=x;
else res++;
}
return tz;
}
int main()
{
scanf("%d %d", &n, &k);
for(int i=1;i<=n;i++)
scanf("%d",spice+i);
for(int i=1;i<n;i++){
int t1,t2;
scanf("%d %d", &t1, &t2);
niz[t1].pb(t2);
niz[t2].pb(t1);
}
dfs(1,0);
printf("%d",res);
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... |