Submission #286762


Source Code Expand

Copy
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;
int parent[200];
int cnt[200];
int exists[200];
vector<int> edge[200];
pair<int,int> dfs( int x, int prev ){
  int c = 0;
  int dist = 0;
  for( int i = 0 ; i < (int) edge[x].size(); i++ ){
    int nxt = edge[x][i];
    if(nxt != prev){
      pair<int,int> p = dfs(nxt,x);
      if( p.first != 0 ){
        c+= p.first;
        dist+=p.second+2;
      }
    }
  }
  parent[x] = prev;
  c+=exists[x];
  cnt[x] = c;
  return make_pair(c,dist);
}

int main(){
  int n, x;
  cin >> n >>  x;
  for( int i = 0 ; i <n ; i++ ) cin >> exists[i];
  for( int i = 0 ; i < n-1 ; i++ ){
    int s,t;
    cin >> s >> t;
    s--;
    t--;
    edge[s].push_back(t);
    edge[t].push_back(s);
  }
  memset(parent,-1,sizeof(parent));
  memset(cnt,0,sizeof(cnt)); 
  x--;
  pair<int,int> p = dfs(x,x);
  cout << p.second;
  
  return 0;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User yaoshimax
Language C++ (G++ 4.6.4)
Score 0
Code Size 1253 Byte
Status WA
Exec Time 50 ms
Memory 928 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
WA × 2
WA × 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 WA 21 ms 924 KB
subtask0_sample_02.txt WA 23 ms 800 KB
subtask1_line01.txt WA 23 ms 796 KB
subtask1_line02.txt WA 21 ms 800 KB
subtask1_line03.txt WA 25 ms 888 KB
subtask1_line04.txt WA 23 ms 812 KB
subtask1_line05.txt WA 32 ms 924 KB
subtask1_line06.txt WA 29 ms 924 KB
subtask1_random01.txt WA 50 ms 792 KB
subtask1_random02.txt WA 27 ms 800 KB
subtask1_random03.txt WA 23 ms 924 KB
subtask1_random04.txt WA 23 ms 928 KB
subtask1_random05.txt WA 24 ms 924 KB
subtask1_random06.txt WA 22 ms 808 KB
subtask1_random07.txt WA 22 ms 788 KB
subtask1_random08.txt WA 22 ms 928 KB
subtask1_special01.txt WA 21 ms 796 KB
subtask1_special02.txt WA 21 ms 800 KB
subtask1_special03.txt WA 22 ms 808 KB
subtask1_special04.txt WA 23 ms 928 KB