답안 #626725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626725 2022-08-11T17:14:50 Z MilosMilutinovic Burza (COCI16_burza) C++14
0 / 160
115 ms 237932 KB
/**
 *    author:  wxhtzdy
 *    created: 11.08.2022 18:52:59
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, k;
  cin >> n >> k;
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> dep(n);
  vector<int> dfn(n);
  vector<int> dfo(n);
  int T = 0;
  function<void(int, int)> Dfs = [&](int v, int pr) {
    dfn[v] = ++T;        
    for (int u : g[v]) {
      if (u == pr) {
        continue;
      }
      dep[u] = dep[v] + 1;
      Dfs(u, v);    
    } 
    dfo[v] = ++T;
  };
  Dfs(0, 0);
  if (*max_element(dep.begin(), dep.end()) < k) {
    cout << "DA" << '\n';
    return 0;
  }
  vector<vector<int>> at(n);
  for (int i = 0; i < n; i++) {
    at[dep[i]].push_back(i);      
  }
  for (int i = 0; i < n; i++) {
    sort(at[i].begin(), at[i].end(), [&](int u, int v) {
      return dfn[u] < dfn[v];
    });
  }      
  auto isPar = [&](int v, int u) {
    return dfn[v] <= dfn[u] && dfo[u] <= dfo[v];
  };
  vector<vector<vector<int>>> can(n, vector<vector<int>>(n, vector<int>(n, -1)));
  function<bool(int, int, int)> Solve = [&](int l, int r, int dep) {      
    if (can[l][r][dep] != -1) {
      return can[l][r][dep] == 1;
    }
    can[l][r][dep] = 0;           
    for (int v : at[dep]) {
      int L = 0, R = 0;
      {
        int low = 0, high = at[k].size() - 1;
        while (low <= high) {
          int mid = low + high >> 1;
          if (isPar(v, at[k][mid])) {
            L = mid;
            high = mid - 1;
          } else {
            if (dfn[v] > dfn[at[k][mid]]) {
              low = mid + 1;
            } else {
              high = mid - 1;
            }
          }
        }
      }
      {
        int low = 0, high = at[k].size() - 1;
        while (low <= high) {
          int mid = low + high >> 1;
          if (isPar(v, at[k][mid])) {
            R = mid;
            low = mid + 1;
          } else {        
            if (dfn[v] > dfn[at[k][mid]]) {
              low = mid + 1;
            } else {
              high = mid - 1;
            }
          }
        }
      }                                                                                             
      if (!isPar(v, at[k][L])) {
        continue;
      }   
      bool ok = true;
      if (L > l) {
        ok &= Solve(l, L - 1, dep + 1);
      }
      if (R < r) {
        ok &= Solve(R + 1, r, dep + 1);
      }
      if (ok) {
        can[l][r][dep] = 1;
      }
    }
    return can[l][r][dep] == 1;
  };
  cout << (Solve(0, (int) at[k].size() - 1, 1) ? "DA" : "NE") << '\n';                                              
  return 0;
}

Compilation message

burza.cpp: In lambda function:
burza.cpp:65:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |           int mid = low + high >> 1;
      |                     ~~~~^~~~~~
burza.cpp:81:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   81 |           int mid = low + high >> 1;
      |                     ~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 123428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 98 ms 221392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 99 ms 229536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 95 ms 214436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 98 ms 201232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 104 ms 227116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 115 ms 237932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 81 ms 153624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 89056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 148300 KB Output isn't correct
2 Halted 0 ms 0 KB -