# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
536521 | Asymmetry | Chase (CEOI17_chase) | C++17 | 4064 ms | 95772 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Autor: Bartłomiej Czarkowski
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif
const int N = 101'000;
const int V = 107;
int n, m, a, b;
int t[N];
int pr[N];
long long sum[N];
vector<int> v[N];
long long dp[N][V];
void dfd(int x) {
for (int i : v[x]) {
if (i == pr[x]) {
continue;
}
pr[i] = x;
dfd(i);
}
}
void dfs(int x) {
for (int i = 0; i <= m; ++i) {
dp[x][i] = 0;
}
for (int i : v[x]) {
if (i == pr[x]) {
continue;
}
dfs(i);
for (int j = 0; j <= m; ++j) {
dp[x][j] = max(dp[x][j], dp[i][j]);
}
}
for (int j = m; j; --j) {
dp[x][j] = max(dp[x][j], dp[x][j - 1] + sum[x] - t[pr[x]]);
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &t[i]);
}
for (int i = 1; i < n; ++i) {
scanf("%d%d", &a, &b);
v[a].push_back(b);
v[b].push_back(a);
}
for (int i = 1; i <= n; ++i) {
for (int j : v[i]) {
sum[i] += t[j];
}
}
long long odp = 0;
for (int i = 1; i <= n; ++i) {
pr[i] = 0;
dfd(i);
dfs(i);
for (int j = 0; j <= m; ++j) {
odp = max(odp, dp[i][j]);
}
}
printf("%lld\n", odp);
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... |