Submission #853369

# Submission time Handle Problem Language Result Execution time Memory
853369 2023-09-24T08:46:31 Z stefanneagu Power Plant (JOI20_power) C++17
0 / 100
1 ms 348 KB
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

const int nmax = 2e4 + 2;

vector<vector<int>> adj;
int sum[nmax], f[nmax], viz[nmax];
string s;

void dfs(int i, int add) {
    sum[i] += add;
    for(auto it : adj[i]) {
        if(!viz[it]) {
            viz[it] = 1;
            if(s[it] == '1') {
                add = 1;
            }
            dfs(it, add);
        }
    }
}

int main() {
    int n;
    cin >> n;
    adj.resize(n + 1);
    for(int i = 1; i < n; i ++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        f[a] ++;
        f[b] ++;
    }
    cin >> s;
    s = '0' + s;
    for(int i = 1; i <= n; i ++) {
        if(f[i] == 1) {
            memset(viz, 0, sizeof(viz));
            dfs(i, 0);
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i ++) {
        if(s[i] == '1') {
            ans ++;
            int cnt = 0;
            for(auto it : adj[i]) {
                if(sum[it]) {
                    cnt ++;
                }
            }
            if(cnt > 1) {
                ans --;
            }
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -