이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int n_max = 2 * 1e5 + 7;
vector<int> graph[n_max];
int power_generator[n_max];
int ans;
int DFS(int v, int p){
int sum = 0;
int max_vallue = 0;
for(auto u: graph[v]){
if(u != p){
int vallue = DFS(u ,v);
sum += vallue;
max_vallue = max(max_vallue, vallue);
}
}
int ans_tym = 0;
if(power_generator[v] == 1){
ans_tym = max(sum - 1, 1);
if(sum == max_vallue){
ans = max(ans, sum + 1);
}
if(sum == max_vallue + 1){
ans = max(ans, sum);
}
}else{
ans_tym = sum;
}
ans = max(ans, ans_tym);
return ans_tym;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
ans = 0;
int n;
cin >> n;
for(int i = 0; i < n - 1; i++){
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
string s;
cin >> s;
for(int i = 0; i < n; i++){
if(s[i] == '1'){
power_generator[i+1] = 1;
}
}
ans = 0;
DFS(1, 0);
cout << ans << '\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... |