#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define dl double long
using namespace std;
const int N = 5e5 + 7;
const int M = 20 + 7;
const ll mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
int ans;
int a[N];
int d[N];
vector < int > v[N];
void dfs( int x , int p )
{
vector < int > g;
for( auto y : v[x] ){
if( y == p )continue;
dfs( y , x );
d[x] += d[y];
}
if( a[x] ){
d[x] -= 1;
d[x] = max( d[x] , 1 );
if( x != 0 )ans = max( ans , d[x] + 1 );
}
ans = max( ans , d[x] );
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
cin >> n;
for( int i = 1; i < n; i++ ){
int x,y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
for( int i = 1; i <= n; i++ ){
char c;
cin >> c;
a[i] = c - '0';
}
dfs( 1 , 1 );
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
12032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
12032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
12032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |