| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 312458 | colazcy | Paprike (COI18_paprike) | C++17 | 64 ms | 15992 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 1e5 + 100;
inline int read(){
int x = 0;char c = getchar();
while(!isdigit(c))c = getchar();
while(isdigit(c))x = x * 10 + c - '0',c = getchar();
return x;
}
int n,k,ans,val[maxn];
vector<int> G[maxn];
inline void addedge(int u,int v){G[u].push_back(v);}
inline int dfs(int u,int faz = -1){
int res = val[u];
vector<int> vec;
for(int i = 0;i < G[u].size();i++){
int v = G[u][i];
if(v == faz)continue;
vec.push_back(dfs(v,u));
}
sort(vec.begin(),vec.end(),[](int a,int b){return a < b;});
int i = 0;
for(;i < vec.size() && res + vec[i] <= k;i++)res += vec[i];
ans += vec.size() - i;
return res;
}
int main(){
// freopen("paprike.in","r",stdin);
// freopen("paprike.out","w",stdout);
n = read(),k = read();
for(int i = 1;i <= n;i++)val[i] = read();
for(int u,v,i = 1;i < n;i++)
u = read(),v = read(),addedge(u,v),addedge(v,u);
dfs(1);
printf("%d\n",ans);
fclose(stdin);
fclose(stdout);
return 0;
}컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
