Submission #30477

# Submission time Handle Problem Language Result Execution time Memory
30477 2017-07-23T14:41:50 Z sampriti Network (BOI15_net) C++14
0 / 100
3 ms 13896 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>

using namespace std;

vector<int> G[500001];
vector<int> leaves;

void dfs(int i, int p) {
  bool leaf = true;

  for(int u: G[i]) {
    if(u == p) continue;

    leaf = false;
    dfs(u, i);
  }

  if(leaf) leaves.push_back(i);
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0);

  int N; cin >> N;

  for(int i = 0; i < N - 1; i++) {
    int a, b; cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(1, 0);
  if(G[1].size() == 1) leaves.push_back(1);

  int ans = (leaves.size() + 1)/2;

  cout << ans << endl;
  return 0;

  for(int i = 0; i < ans; i++) {
    assert((i + leaves.size()/2) < leaves.size());
    cout << leaves[i] << " " << leaves[i + leaves.size()/2] << endl;
  }
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 13896 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 13896 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 13896 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -