#include <iostream>
#include <vector>
#include <map>
using namespace std;
int n;
vector<pair<int, int>> edges;
vector<vector<int>> g;
vector<map<int, int>> dp;
string s;
int dfs(int u, int par) {
if (dp[u].find(par) != dp[u].end()) return dp[u][par];
int ret = 0;
for (int v : g[u]) {
if (v != par) ret += dfs(v, u);
}
if (s[u] == '1') ret = max(1, ret - 1);
dp[u][par] = ret;
return ret;
}
int solve() {
dp.resize(n);
int ans = 0;
for (auto [a, b] : edges) {
ans = max(ans, dfs(a, b) + dfs(b, a));
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
edges.resize(n - 1), g.resize(n);
for (auto &[a, b] : edges) {
cin >> a >> b;
a--, b--;
g[a].push_back(b);
g[b].push_back(a);
}
cin >> s;
cout << solve() << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |