| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 48463 | WLZ | Paprike (COI18_paprike) | C++17 | 72 ms | 20108 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
const int INF = 1e9;
const int MAXN = 1e5 + 5;
const ll LINF = 1e18;
const double pi = acos(-1);
const double EPS = 1e-9;
template <class T> using MinPQ = priority_queue<T, vector<T>, greater<T>>;
template <class T> using MaxPQ = priority_queue<T>;
int n;
ll k;
int a[MAXN];
vector< vector<int> > g;
bitset<MAXN> vis;
void bfs(int s) {
queue<int> q; q.push(s);
ll curSize = a[s];
vis[s] = 1;
while (!q.empty()) {
int u = q.front(); q.pop();
for (int& v : g[u]) {
if (!vis[v] && (ll) a[v] + curSize <= k) {
q.push(v);
curSize += a[v];
vis[v] = 1;
}
}
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
scanf("%d %lld", &n, &k);
g.assign(n, vector<int>());
for (int i = 0; i < n; i++) scanf("%d", a + i);
for (int i = 0; i < n - 1; i++) {
int x, y;
scanf("%d %d", &x, &y); --x; --y;
g[x].emplace_back(y);
g[y].emplace_back(x);
}
int ans = 0;
for (int i = 0; i < n; i++) {
if ((int) g[i].size() == 1 && !vis[i]) {
ans++;
bfs(i);
}
}
for (int i = 0; i < n; i++) {
if (!vis[i]) {
ans++;
bfs(i);
}
}
printf("%d\n", ans - 1);
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... | ||||
