Submission #286781


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <queue>
const int N_MAX = 100;
using namespace std;

int N , x;
int exist[N_MAX + 1];
vector<int> v[N_MAX+1];
queue<int> q;
int flag[N_MAX+1];

int main(){
  cin >> N >> x;
  for(int i=0;i<N;i++){
    cin >> exist[i];
  }
  for(int i=0;i<N-1;i++){
    int a,b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int depth = 0;
  int ans = 0;
  q.push(x);
  flag[x] = 1;
  while(!q.empty()){
    int qsize = q.size();
    for(int j=0;j<qsize;j++){
      int pos = q.front();
      q.pop();
      if(exist[pos - 1] == 1){
        ans += depth*2;
      }
      for(int i=0;i<v[pos].size();i++){
        if(flag[v[pos][i]] == 0){
          q.push(v[pos][i]);
          flag[v[pos][i]] = 1;
        }
      }
    }
    depth++;
  }

  cout << ans << endl;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User gamelove765
Language C++ (G++ 4.6.4)
Score 0
Code Size 865 Byte
Status WA
Exec Time 24 ms
Memory 920 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 7
WA × 13
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 23 ms 796 KB
subtask0_sample_02.txt AC 22 ms 732 KB
subtask1_line01.txt AC 22 ms 808 KB
subtask1_line02.txt WA 22 ms 804 KB
subtask1_line03.txt WA 21 ms 920 KB
subtask1_line04.txt WA 22 ms 676 KB
subtask1_line05.txt WA 21 ms 800 KB
subtask1_line06.txt AC 23 ms 920 KB
subtask1_random01.txt WA 21 ms 804 KB
subtask1_random02.txt WA 21 ms 672 KB
subtask1_random03.txt WA 22 ms 800 KB
subtask1_random04.txt WA 22 ms 804 KB
subtask1_random05.txt WA 22 ms 800 KB
subtask1_random06.txt WA 23 ms 804 KB
subtask1_random07.txt WA 22 ms 800 KB
subtask1_random08.txt WA 24 ms 804 KB
subtask1_special01.txt AC 22 ms 752 KB
subtask1_special02.txt AC 21 ms 796 KB
subtask1_special03.txt AC 23 ms 736 KB
subtask1_special04.txt WA 24 ms 796 KB