This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/******************************
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |