| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 531891 | aryan12 | Power Plant (JOI20_power) | C++17 | 4 ms | 4940 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
string power_plants;
const int N = 2e5 + 5;
vector<int> g[N];
int dp[N][2];
int ans = 0;
void dfs(int node, int par) {
int sum = 0, maxi = 0;
for(int i = 0; i < g[node].size(); i++) {
if(g[node][i] == par) continue;
dfs(g[node][i], node);
sum += max(dp[g[node][i]][0], dp[g[node][i]][1] - 2);
maxi = max({maxi, dp[g[node][i]][0], dp[g[node][i]][1] - 2});
}
if(power_plants[node - 1] == '0') {
dp[node][0] = sum;
dp[node][1] = 1;
}
else {
dp[node][1] = maxi + 1;
dp[node][0] = max(1LL, sum - 1);
}
}
void Solve() {
int n;
cin >> n;
for(int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
cin >> power_plants;
dfs(1, -1);
cout << max({ans, dp[1][0], dp[1][1]}) << "\n";
}
int32_t main() {
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--) {
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
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... | ||||
