| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 454250 | HillcrestEnigma | Paprike (COI18_paprike) | C++17 | 91 ms | 19084 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/* #define endl '\n' */
#define indexed_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
const int MOD = 1e9+7;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1};
int n, k, a, b;
int ans = 0;
int h[100000] = {0};
vi graph[100000];
int dfs(int v, int p) {
vi spy;
/* cout << v << ": "; */
/* for (int c:graph[v]) cout << c << " "; */
/* cout << endl; */
for (int c:graph[v]) if (c != p) spy.push_back(dfs(c, v));
sort(all(spy));
int res = h[v];
for (int i=0; i<spy.size(); i++) {
if (res + spy[i] > k) {
ans += spy.size() - i;
return res;
}
res += spy[i];
}
return res;
}
void _main() {
cin >> n >> k;
for (int i=0; i<n; i++) {
cin >> h[i];
}
for (int i=0; i<n-1; i++) {
cin >> a >> b;
--a; --b;
graph[a].push_back(b);
graph[b].push_back(a);
}
dfs(0, -1);
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
_main();
return 0;
}컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
