답안 #853401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853401 2023-09-24T09:34:50 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 cum_from, int add) {
    if(add == 1) {
        if(cum_from == 2) {
            sum[i] = add;
        }
    }
    if(cum_from == 1) {
        cum_from ++;
    }
    for(auto it : adj[i]) {
        if(!viz[it]) {
            viz[it] = 1;
            int curr_add = add;
            if(s[it] == '1') {
                curr_add = 1;
            }
            if(s[i] == '1' && cum_from == 0) {
                dfs(it, cum_from + 1, curr_add);
            } else {
                dfs(it, cum_from, curr_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));
        viz[i] = 1;
        if(s[i] == '0') {
            dfs(i, 0, 0);
        } else {
            dfs(i, 0, 1);
        }
    }
    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 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 344 KB Output isn't correct
6 Halted 0 ms 0 KB -