Submission #961189

# Submission time Handle Problem Language Result Execution time Memory
961189 2024-04-11T16:27:57 Z imann Burza (COCI16_burza) C++17
0 / 160
1 ms 452 KB
#include <iostream>
#include <map>
#include <vector>
#include <array>
#include <queue>
#include <set>

const int MAX_N = 400 + 2;

std::array<std::vector<int>, MAX_N> graph;
std::array<std::vector<int>, MAX_N> children;
std::map<int, int> toParent;
std::map<int, bool> color;
std::array<int, MAX_N> dp;

void bfs() {
  std::queue<int> q;
  q.push(1);
  color[1] = true;
  while (!q.empty()) {
    int n = q.front();
    q.pop();
    color[n] = true;
    for (int c : graph[n]) {
      if (!color[c]) {
        children[n].push_back(c);
        toParent[c] = n;
        q.push(c);
      }
    }
  }
}

int solve(int n) {
  bfs();

  std::set<int> nexts;
  for (int i = 1; i <= n; ++i) {
    if (children[i].size() == 0 && toParent[i] != 0) {
      nexts.insert(toParent[i]);
    }
  }

  while (!nexts.empty()) {
    std::set<int> nNexts;
    for (int n : nexts) {
      int max = -1, nmax = -1;
      for (int c : children[n]) {
        if (dp[c] > max) {
          nmax = max;
          max = dp[c];
        } else if (dp[c] > nmax) {
          nmax = dp[c];
        }
      }
      dp[n] = nmax + 1;
      if (toParent[n] != 0)
        nNexts.insert(toParent[n]);
    }
    nexts = nNexts;
  }

  return dp[1];
}

int main() {
  int n, k; std::cin >> n >> k;
  for (int i = 0; i < n - 1; ++i) {
    int a, b; std::cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  if (k <= solve(n)) {
    std::cout << "NE" << std::endl;
  } else {
    std::cout << "DA" << std::endl;
  }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -