Submission #1455119


Source Code Expand

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

using ll = long long int;

vector<int> tree[110];
int jewel[110] = {};
int f[110] = {};

int solve(int p){
    if(f[p]){
        return 0;
    }
    
    f[p] = true;
    
    int res = 0;
    
    for(const int & next : tree[p]){
        res += solve(next);
    }
    
    if(jewel[p] || res != 0){
        res += 1;
    }
    
    return res;
}

int main(void){
    
    int n,x;
    cin >> n >> x;
    
    for(int i = 0; i < n; i++){
        cin >> jewel[i+1];
    }
    for(int i = 0; i < n-1; i++){
        int a,b;
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    
    cout << max(0,solve(x)-1) * 2 << endl;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User nasatame
Language C++14 (GCC 5.4.1)
Score 100
Code Size 790 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 20
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask1_line01.txt, subtask1_line02.txt, subtask1_line03.txt, subtask1_line04.txt, subtask1_line05.txt, subtask1_line06.txt, subtask1_random01.txt, subtask1_random02.txt, subtask1_random03.txt, subtask1_random04.txt, subtask1_random05.txt, subtask1_random06.txt, subtask1_random07.txt, subtask1_random08.txt, subtask1_special01.txt, subtask1_special02.txt, subtask1_special03.txt, subtask1_special04.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 1 ms 256 KB
subtask0_sample_02.txt AC 1 ms 256 KB
subtask1_line01.txt AC 1 ms 256 KB
subtask1_line02.txt AC 1 ms 256 KB
subtask1_line03.txt AC 1 ms 256 KB
subtask1_line04.txt AC 1 ms 256 KB
subtask1_line05.txt AC 1 ms 256 KB
subtask1_line06.txt AC 1 ms 256 KB
subtask1_random01.txt AC 1 ms 256 KB
subtask1_random02.txt AC 1 ms 256 KB
subtask1_random03.txt AC 1 ms 256 KB
subtask1_random04.txt AC 1 ms 256 KB
subtask1_random05.txt AC 1 ms 256 KB
subtask1_random06.txt AC 1 ms 256 KB
subtask1_random07.txt AC 1 ms 256 KB
subtask1_random08.txt AC 1 ms 256 KB
subtask1_special01.txt AC 1 ms 256 KB
subtask1_special02.txt AC 1 ms 256 KB
subtask1_special03.txt AC 1 ms 256 KB
subtask1_special04.txt AC 1 ms 256 KB