Submission #369422

#TimeUsernameProblemLanguageResultExecution timeMemory
369422jhnah917Power Plant (JOI20_power)C++14
100 / 100
196 ms26988 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, R; bool S[202020]; vector<int> G[202020]; int DFS(int v, int b){ int t1 = 0, t2 = S[v]; for(const auto &i : G[v]){ if(i == b) continue; int t = DFS(i, v); t1 += t; t2 = max(t2, t + S[v]); } t1 = max<int>(S[v], t1 - S[v]); R = max({R, t1, t2}); return t1; } 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 == '1'; } DFS(1, -1); cout << R; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...