이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 2e5+7;
ll n, dp[mxn], ans = 0;
vector<vector<ll>> g(mxn);
bool c[mxn];
void dfs(ll u, ll v)
{
for (ll i : g[u]) if (i != v)
{
dfs(i,u);
dp[u] += dp[i];
ans = max(ans, dp[i]+c[u]);
}
dp[u] = max(dp[u]-c[u], (ll)c[u]);
ans = max(ans, dp[u]);
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
cin >> n;
for (ll i = 1; i < n; i++)
{
ll a, b; cin >> a >> b;
g[a].pb(b); g[b].pb(a);
}
string s; cin >> s;
for (ll i = 1; i <= n; i++) c[i] = (s[i-1]-'0');
dfs(1,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... |