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> v[200005];
int din[200005],val[200005];
int dfs(int x,int tata)
{
int i,maxim=0,maxim2=0;
for (i=0; i<v[x].size(); i++)
{
if (v[x][i]!=tata)
{
maxim=max(maxim,dfs(v[x][i],x));
din[x]+=din[v[x][i]];
maxim2=max(maxim2,din[v[x][i]]);
}
}
din[x]=max(val[x],din[x]-val[x]);
return max(maxim,max(din[x],maxim2+val[x]));
}
int n,i,x,y;
char ch;
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(0);
#ifdef HOME
ifstream cin("date.in");
ofstream cout("date.out");
#endif // HOME
cin>>n;
for (i=1; i<=n-1; i++)
{
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
for (i=1; i<=n; i++)
{
cin>>ch;
val[i]=ch-'0';
}
cout<<dfs(1,0);
return 0;
}
Compilation message (stderr)
power.cpp: In function 'int dfs(int, int)':
power.cpp:9:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for (i=0; i<v[x].size(); i++)
| ~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |