#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 2e5 + 7;
int n, dp[mxN], ans;
string s;
bool vis[mxN];
vector<int> w[mxN];
void DFS(int j)
{
vis[j] = 1;
for (int i : w[j])
{
if (vis[i])
continue;
DFS(i);
if (s[j] == '1')
ans = max(ans, dp[i] + 1);
dp[j] += dp[i];
}
if (s[j] == '1')
dp[j] = max(dp[j] - 1, 1);
ans = max(ans, dp[j]);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
cin >> n;
for (int i = 1; i < n; i++)
{
int u, v;
cin >> u >> v;
w[u].push_back(v);
w[v].push_back(u);
}
cin >> s;
s = ' ' + s;
ans = 0;
DFS(1);
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |