제출 #312547

#제출 시각아이디문제언어결과실행 시간메모리
312547Jarif_RahmanPower Plant (JOI20_power)C++17
47 / 100
1573 ms12204 KiB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n;
str s;
vector <vector<int>> v;
ll ans =  0;
int snd;
ll dfs(int nd, int ss){
    ll r = '0'-s[nd];
    if(ss == -1 && v[nd].size() == 1) r = 1;
    for(int x: v[nd]) if(x != ss) r+=dfs(x, nd);
    //cout << nd << " " << r << " " << s[nd] - '0' << " de\n";
    return max(r, (ll)s[nd] - '0');
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    v = vector<vector<int>> (n+1);
    for(int i = 1; i < n; i++){
        int a, b; cin >> a >> b;
        v[a].pb(b);
        v[b].pb(a);
    }
    cin >> s;
    s = "x"+s;
    for(int i = 1; i <= n; i++) if(s[i] == '1') ans = max(ans, dfs(i, -1));
    //cout << dfs(2, -1) << "\n";
    cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...