답안 #853375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853375 2023-09-24T08:59: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 = 2e3 + 2;

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

void dfs(int i, int add) {
    if(sum[i] == 0) {
        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 ++) {
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -