Submission #286685


Source Code Expand

Copy
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<numeric>
#include<functional>
#include<complex>
#include<cassert>

using namespace std;
#define BET(a,b,c) ((a)<=(b)&&(b)<(c))
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(),(x).end()
#define MP make_pair
#define CLS(x,val) memset((x) , val , sizeof(x)) 
#define FOR_EACH(it,v) for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++)
typedef long long ll_t;
typedef long double ld_t;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef complex<int> xy;

VVI adj;
int h[111];

pair<int,int> dfs(int pos, int pre){
    int val = 0;
    int starNum = 0;
    if(h[pos]) starNum = 1;
    for(auto next : adj[pos]){
        if(next == pre) continue;
        auto sub = dfs(next, pos);
        if(sub.second == 0) continue;
        val += sub.first + 2;
    }
    return MP(val, starNum);
}

int main()
{
    int n,x;
    cin>>n>>x;
    FOR(i,n) cin>>h[i];
    adj.resize(n);
    FOR(i,n-1){
        int a,b;
        cin>>a>>b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cout<<dfs(x, -1).first<<endl;
    return 0;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User EmK
Language C++11 (GCC 4.8.1)
Score 0
Code Size 1407 Byte
Status WA
Exec Time 300 ms
Memory 928 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 1
WA × 1
AC × 4
WA × 12
RE × 4
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 22 ms 796 KB
subtask0_sample_02.txt WA 21 ms 804 KB
subtask1_line01.txt RE 300 ms 800 KB
subtask1_line02.txt WA 22 ms 804 KB
subtask1_line03.txt WA 22 ms 800 KB
subtask1_line04.txt RE 257 ms 804 KB
subtask1_line05.txt RE 260 ms 672 KB
subtask1_line06.txt AC 22 ms 792 KB
subtask1_random01.txt WA 22 ms 800 KB
subtask1_random02.txt WA 23 ms 732 KB
subtask1_random03.txt WA 22 ms 792 KB
subtask1_random04.txt WA 23 ms 800 KB
subtask1_random05.txt WA 23 ms 928 KB
subtask1_random06.txt WA 22 ms 800 KB
subtask1_random07.txt WA 22 ms 796 KB
subtask1_random08.txt WA 22 ms 924 KB
subtask1_special01.txt RE 256 ms 792 KB
subtask1_special02.txt WA 21 ms 804 KB
subtask1_special03.txt AC 22 ms 736 KB
subtask1_special04.txt AC 21 ms 928 KB