이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> gra;
string s;int n;
pair<int,int> dfs(int x, int p){
int boff = (s[x] == '1'), bon = (s[x] == '1');
int su = 0;
for(auto i : gra[x]){
if(i == p)continue;
auto now = dfs(i,x);
boff = max({boff,now.first,now.second+(s[x] == '1')});
su+=now.second;
}
bon = max(bon,su-(s[x] == '1'));
boff = max(boff,bon);
return {boff,bon};
}
int main(){
cin >> n;
gra.resize(n);
for(int i = 0; i < n-1; ++i){
int a, b; cin >> a >> b;
a--; b--;
gra[a].push_back(b);
gra[b].push_back(a);
}
cin >> s;
cout << dfs(0,0).first << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |