# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
293672 | AlexLuchianov | Power Plant (JOI20_power) | C++14 | 4 ms | 4992 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <algorithm>
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 200000;
std::vector<int> g[1 + nmax];
char active[1 + nmax];
int dp[1 + nmax];
void dfs(int node, int parent) {
for(int h = 0; h < g[node].size(); h++) {
int to = g[node][h];
if(to == parent)
g[node].erase(g[node].begin() + h);
}
dp[node] = -(active[node] - '0');
for(int h = 0; h < g[node].size(); h++) {
int to = g[node][h];
dfs(to, node);
dp[node] += dp[to];
}
dp[node] = std::max(dp[node], active[node] - '0');
}
int solve(int node) {
int result = 0;
for(int h = 0; h < g[node].size(); h++) {
int to = g[node][h];
result = std::max(result, solve(to));
result = std::max(result, dp[to] + active[node] - '0');
}
return result;
}
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int n;
std::cin >> n;
for(int i = 1; i < n; i++) {
int a, b;
std::cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
std::cin >> (active + 1);
dfs(1, 0);
std::cout << solve(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... |