제출 #1354631

#제출 시각아이디문제언어결과실행 시간메모리
1354631SulAPower Plant (JOI20_power)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define popcount __builtin_popcount
#define all(a) (a).begin(), (a).end()
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T,null_type,less_equal<>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 200000;
vector<int> adj[N];
string gen;

int dfs(int u, int p = -1) {
    if (gen[u] == '1') return 1;
    int res = 0;
    for (int v : adj[u]) {
        if (v != p) res += dfs(v, u);
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    for (int i = 0, u, v; i < n-1; i++) {
        cin >> u >> v;
        adj[--u].push_back(--v);
        adj[v].push_back(u);
    }
    cin >> gen;
    int anas = 0;
    for (int i = 0; i < n; i++) {
        anas = max(anas, dfs(i));
        int cur = -1;
        for (int j : adj[i])
            cur += dfs(i, j);
        anas = max(anas, cur);
    }
    cout << anas;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...