# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
103754 | E869120 | Chase (CEOI17_chase) | C++14 | 80 ms | 8716 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)
long long N, V, p[1 << 17], c[1 << 17], ret1, ret2, maxn = 0;
vector<int>X[1 << 17];
bool used[1 << 17];
void dfs(int pos, int dep) {
maxn = max(maxn, abs(ret1 - ret2));
used[pos] = true;
if (dep == V) return;
for (int to : X[pos]) {
if (used[to] == true) continue;
for (int r : X[to]) { c[r]++; if (c[r] == 1) ret2 += p[r]; }
dfs(to, dep + 1);
for (int r : X[to]) { c[r]--; if (c[r] == 0) ret2 -= p[r]; }
}
}
int main() {
scanf("%lld%lld", &N, &V);
for (int i = 1; i <= N; i++) scanf("%lld", &p[i]);
for (int i = 1; i <= N - 1; i++) {
long long u, v; scanf("%lld%lld", &u, &v);
X[u].push_back(v);
X[v].push_back(u);
}
for (int i = 1; i <= N; i++) X[i].push_back(i);
for (int i = 1; i <= N; i++) {
if (N >= 2000 && i >= 2) break;
for (int j = 1; j <= N; j++) used[j] = false;
ret1 = p[i]; ret2 = 0;
for (int j = 1; j <= N; j++) c[j] = 0;
for (int j : X[i]) { c[j] = 1; ret2 += p[j]; }
dfs(i, 1);
}
cout << maxn << endl;
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... |