Submission #369419

#TimeUsernameProblemLanguageResultExecution timeMemory
369419jhnah917Power Plant (JOI20_power)C++14
0 / 100
5 ms5228 KiB
/****************************** Author: jhnah917(Justice_Hui) g++ -std=c++17 -DLOCAL ******************************/ #include <bits/stdc++.h> #define x first #define y second #define all(v) v.begin(), v.end() #define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end()) #define IDX(v, x) lower_bound(all(v), x) - v.begin() using namespace std; using uint = unsigned; using ll = long long; using ull = unsigned long long; int N, S[202020]; vector<int> G[202020]; int D[202020], R; void DFS(int v, int b){ int t1 = 0, t2 = S[v]; for(const auto &i : G[v]){ if(i == b) continue; DFS(i, v); t1 += D[i]; t2 = max(t2, D[i] + S[v]); } D[v] = max(S[v], t1 - S[v]); R = max({R, t1, t2}); } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N; for(int i=1; i<N; i++){ int s, e; cin >> s >> e; G[s].push_back(e); G[e].push_back(s); } for(int i=1; i<=N; i++){ char c; cin >> c; S[i] = c - '0'; } DFS(1, -1); cout << R; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...