답안 #1046303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046303 2024-08-06T12:42:30 Z sleepntsheep File Paths (BOI15_fil) C
33 / 100
120 ms 704 KB
#include <stdio.h>
#include <stdlib.h>
 #include<assert.h>
#define N 6005
 
int n_, s, n, m, k, m_, par[N], *eh[N], eo[N], dep[N], chain[N], o;
 
int cc(const void *i, const void *j) {
  return *(int*)i-*(int*)j;
}
 
void pus(int i, int j) {
  int o = eo[i]++;
  if (!o) eh[i] = (int*)malloc(sizeof **eh * 2);
  else if (0 == (o & o - 1)) eh[i] = (int*)realloc(eh[i], 2 * o * sizeof **eh);
  eh[i][o] = j;
}
 
void efs(int u) {
  assert(0);
  dep[u] = 1e9;
  for (int j = 0; j < eo[u]; j += 2) if (eh[u][j] != par[u])
    efs(eh[u][j]);
}
 
void dfs(int u) {
  for (int j = 0; j < eo[u]; j += 2) if (eh[u][j] != par[u]) {
    int v = eh[u][j], l = eh[u][j+1];
    dep[v] = l + dep[u];
    if (dep[v] > k)
      efs(v);
    else
      dfs(v);
  }
}
 
int main(void) {
  scanf("%d%d%d%d", &n, &m, &k, &s);
  n_ = n;
  m_ = m;
  n = n + m;
  ++s;
 
  for (int p, l, i = 1; i <= n; ++i) {
    scanf("%d%d", &p, &l);
    pus(par[i] = p, i);
    pus(p, l + 1);
  }
 
  dfs(0);
 
  /* sub 2 */
  for (int i = n_ + 1; i <= n; ++i) {
    if (dep[i] == k) {
      puts("YES");
      continue;
    }
 
    o = 0;
    for (int cur = i; cur != 0; cur = par[cur])
      if (cur <= n_)
        chain[o++] = dep[i] - dep[cur];
    chain[o++] = dep[i];
 
    qsort(chain, o, sizeof *chain, cc);
 
    for (int j = 0; j <= n_; ++j) {
      int left = k - s - dep[j];
      if (left > 0) {
        int md, lb = 0, ub = o;
        while (ub - lb > 1)
          if (chain[md = lb + (ub - lb) / 2] <= left) lb = md;
          else ub = md;
        if (chain[lb] == left) {
          puts("YES");
          goto Next;
        }
      }
    }
 
 
    puts("NO");
Next:;
  }
}

Compilation message

fil.c: In function 'pus':
fil.c:15:24: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   15 |   else if (0 == (o & o - 1)) eh[i] = (int*)realloc(eh[i], 2 * o * sizeof **eh);
      |                      ~~^~~
fil.c: In function 'main':
fil.c:38:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d%d%d%d", &n, &m, &k, &s);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fil.c:45:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     scanf("%d%d", &p, &l);
      |     ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 604 KB Output is correct
2 Correct 17 ms 604 KB Output is correct
3 Correct 16 ms 604 KB Output is correct
4 Correct 16 ms 620 KB Output is correct
5 Correct 107 ms 600 KB Output is correct
6 Correct 104 ms 604 KB Output is correct
7 Correct 115 ms 704 KB Output is correct
8 Correct 118 ms 604 KB Output is correct
9 Correct 16 ms 600 KB Output is correct
10 Correct 9 ms 600 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 120 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -