이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, x, y, answer = 0;
string power;
vector<ll> adj[200005];
ll dp[200005], ans[200005];
vector<ll> visited;
void dfs(ll from)
{
visited[from] = true;
ll summ = 0, maxx = 0;
for (ll u: adj[from])
{
if (visited[u]) continue;
dfs(u);
summ+=dp[u];
maxx = max(maxx, dp[u]);
}
if (power[from-1]=='1') {
ans[from] = max(summ-1, maxx + 1);
dp[from] = max(1LL, summ-1);
}
else {
ans[from] = dp[from] = summ;
}
answer = max(answer, ans[from]);
}
int main()
{
cin>>n;
for (ll i=0; i<n-1; ++i)
{
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
}
cin >> power;
visited.assign(n+1, false);
dfs(1);
cout<<answer<<"\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... |