#include <bits/stdc++.h>
#define ii pair<int,int>
#define f first
#define s second
#define pb push_back
#define int long long
#define endl '\n'
using namespace std;
const int MAXN = 1e18;
int mod = 1e9 + 7;
int a[200005];
int dp[200005];
string state;
vector<int> w[200005];
int ans = 0;
void DFS(int u,int par)
{
int cnt = 0;
for(int v:w[u])
{
if(v == par)
{
continue;
}
DFS(v,u);
dp[u] += dp[v];
cnt = max(cnt,dp[v]);
}
if(state[u - 1] = '1')
{
ans = max(ans,cnt + 1);
dp[u] = max(1ll,dp[u] - 1);
}
ans = max(ans,dp[u]);
}
void AcSolution()
{
int n;
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 >> state;
cout << ans << endl;
}
signed main()
{
// freopen("BDIGIT.inp", "r",stdin);
// freopen("BDIGIT.out", "w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t--)
{
AcSolution();
}
}
Compilation message
power.cpp: In function 'void DFS(long long int, long long int)':
power.cpp:29:18: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
29 | if(state[u - 1] = '1')
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |