This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
vector<int> haha[200001];
vector<int> dp(200001);
vector<int> col(200001);
void dfs(int a, int t) {
int sb = 0;
for(int v: haha[a]) {
if(v != t) {
dfs(v,a);
sb+=dp[v];
}
}
sb-=col[a];
dp[a] = col[a];
dp[a] = max(dp[a],sb);
}
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int n,a,b,ans = 0;
cin >> n;
for(int i = 0; i < n-1; i++) {
cin >> a >> b;
haha[a].push_back(b);
haha[b].push_back(a);
}
for(int i = 1; i <= n; i++) {
char a;
cin >> a;
if(a == '1') {
col[i] = 1;
}
}
for(int i = 1; i <= n; i++) {
if(col[i]) {
dfs(i,-1);
int sb = 0;
for(int v: haha[i]) {
sb = max(dp[v],sb);
}
sb++;
ans = max(ans,sb);
}
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |