| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 747568 | MilosMilutinovic | Untitled (POI11_dyn) | C++14 | 946 ms | 33008 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, m, a[N], d[N][2];
vector <int> g[N], ord;
bool was[N];
bool check(int f) {
for (int i = 1; i <= n; i++) was[i] = false;
int cnt = 0;
for (int x : ord) {
was[x] = true;
d[x][0] = 1e9;
d[x][1] = (a[x] == 1 ? 0 : -1e9);
for (int y : g[x]) {
if (!was[y]) continue;
d[x][0] = min(d[x][0], d[y][0] + 1);
d[x][1] = max(d[x][1], d[y][1] + 1);
}
if (d[x][0] + d[x][1] <= f) d[x][1] = -1e9;
if (d[x][1] == f) cnt++, d[x][0] = 0, d[x][1] = -1e9;
}
if (d[1][1] >= 0) cnt++;
return cnt <= m;
}
void dfs(int x, int fa) {
for (int y : g[x]) if (y != fa) dfs(y, x);
ord.push_back(x);
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
g[x].push_back(y);
g[y].push_back(x);
}
dfs(1, 1);
int l = 0, r = 1e9, ans = 0;
while (l <= r) {
int mid = l + r >> 1;
if (check(mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
printf("%d\n", ans);
}
컴파일 시 표준 에러 (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... | ||||
| # | 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... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
