이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
vector<int> V[200050];
string str; int a, ans = 0;
int search(int now, int from)
{
if(str[now] == '1')
{
int cnt = 0, mx = 0;
for(int x : V[now])
{
if(x == from) continue;
int t = search(x, now);
cnt += t;
mx = max(mx, t);
}
ans = max(ans, max(mx + 1, cnt - 1));
return max(1, cnt - 1);
}
else
{
int cnt = 0;
for(int x : V[now])
{
if(x == from) continue;
cnt += search(x, now);
}
ans = max(ans, cnt);
return cnt;
}
}
int main()
{
cin >> a;
for(int i=0; i < a - 1; i ++)
{
int x, y; cin >> x >> y;
x --; y --;
V[x].push_back(y);
V[y].push_back(x);
}
cin >> str;
search(0, -1);
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... |