이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* upsolve after reading analysis */
#include <stdio.h>
#include <stdlib.h>
#define N 400
#define K 19
int max(int a, int b) { return a > b ? a : b; }
int *ej[N], eo[N];
void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
int pp[N], tb[N], qu[N], cnt;
void dfs(int p, int i, int d) {
int o;
pp[i] = p;
if (d == 0)
qu[cnt++] = i;
for (o = eo[i]; o--; ) {
int j = ej[i][o];
if (j != p)
dfs(i, j, d - 1);
}
tb[i] = cnt;
}
int main() {
static int dp[1 << K];
int n, k, h, i, j, b, d;
scanf("%d%d", &n, &k);
if (k > K) {
printf("DA\n");
return 0;
}
for (i = 0; i < n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
for (h = 0; h < n - 1; h++) {
scanf("%d%d", &i, &j), i--, j--;
append(i, j), append(j, i);
}
dfs(-1, 0, k);
for (b = 0; b < 1 << k; b++) {
i = dp[b] == cnt ? -1 : qu[dp[b]];
for (d = 0; d < k; d++) {
if ((b & 1 << d) == 0)
dp[b | 1 << d] = max(dp[b | 1 << d], i == -1 ? cnt : tb[i]);
if (i != -1)
i = pp[i];
}
}
printf(dp[(1 << k) - 1] == cnt ? "DA\n" : "NE\n");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
burza.c: In function 'append':
burza.c:15:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
15 | if (o >= 2 && (o & o - 1) == 0)
| ~~^~~
burza.c: In function 'main':
burza.c:41:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | scanf("%d%d", &n, &k);
| ^~~~~~~~~~~~~~~~~~~~~
burza.c:49:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | scanf("%d%d", &i, &j), i--, j--;
| ^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |