Submission #2058934


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <utility>
using namespace std;

int solve(vector< vector<int> > &T, int v, int from){
  int ret = 0, k = 0;
  for(int i = 0; i < T[v].size(); ++i){
    if(T[v][i] != from){
      int t = solve(T,T[v][i],v);
      if(t == 0) ++k;
      ret += t;
    }
  }
  ret += max(0,k-1);
  return ret;
}

int main(){
  int N;
  cin >> N;
  if(N <= 2){
    cout << 1 << endl;
    return 0;
  }
  vector< vector<int> > T(N);
  int x, y;
  for(int i = 0; i < N-1; ++i){
    cin >> x >> y;
    T[x].push_back(y);
    T[y].push_back(x);
  }
  int m = 0, v = -1;
  for(int i = 0; i < N; ++i){
    if(T[i].size() > m){
      m = T[i].size();
      v = i;
    }
  }
  int ans = solve(T,v,v);

  cout << ans << endl;
  return 0;
}

Submission Info

Submission Time
Task E - Antennas on Tree
User TAB
Language C++14 (GCC 5.4.1)
Score 900
Code Size 801 Byte
Status
Exec Time 83 ms
Memory 13440 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt
All 900 / 900 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt
Case Name Status Exec Time Memory
0_00.txt 1 ms 256 KB
0_01.txt 1 ms 256 KB
0_02.txt 1 ms 256 KB
1_00.txt 1 ms 256 KB
1_01.txt 1 ms 256 KB
1_02.txt 1 ms 256 KB
1_03.txt 1 ms 256 KB
1_04.txt 1 ms 256 KB
1_05.txt 1 ms 256 KB
1_06.txt 83 ms 13440 KB
1_07.txt 68 ms 6136 KB
1_08.txt 77 ms 10496 KB
1_09.txt 67 ms 6136 KB
1_10.txt 77 ms 11648 KB
1_11.txt 78 ms 7680 KB
1_12.txt 75 ms 5888 KB
1_13.txt 77 ms 5760 KB
1_14.txt 77 ms 5632 KB
1_15.txt 77 ms 5760 KB
1_16.txt 76 ms 5760 KB
1_17.txt 77 ms 5888 KB
1_18.txt 73 ms 6016 KB
1_19.txt 70 ms 6144 KB
1_20.txt 68 ms 6144 KB
1_21.txt 70 ms 6144 KB
1_22.txt 68 ms 6136 KB