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;
const long long MX=2e5+10;
vector < int > mas[MX];
int dp[MX];
char s[MX];
int ans=0;
void DFS(int zar,int mun)
{
int mx=0;
for(auto u:mas[zar])
{
if(u==mun)
{
continue;
}
DFS(u,zar);
dp[zar]+=max(0,dp[u]);
mx=max(mx,dp[u]);
}
dp[zar]=max((int)(s[zar]=='1'),(dp[zar]-(s[zar]=='1')));
if(s[zar]=='1')
{
ans=max(ans,mx+1);
}
ans=max(ans,dp[zar]);
return;
}
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin>>n;
int a,b;
for(int i=1;i<n;i++)
{
cin>>a>>b;
mas[a].push_back(b);
mas[b].push_back(a);
}
for(int i=1;i<=n;i++)
{
cin>>s[i];
}
DFS(1,0);
cout<<ans<<"\n";
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... |