제출 #636575

#제출 시각아이디문제언어결과실행 시간메모리
636575rainboyJail (JOI22_jail)C11
10 / 100
59 ms16228 KiB
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 120000 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 dd[N], pp[N]; void dfs(int p, int i, int d) { int o; dd[i] = d, pp[i] = p; for (o = eo[i]; o--; ) { int j = ej[i][o]; if (j != p) dfs(i, j, d + 1); } } int main() { int t; scanf("%d", &t); while (t--) { static int ii[2], jj[N]; static char bb[N]; int n, m, h, i, j, line, yes; scanf("%d", &n); for (i = 0; i < n; i++) ej[i] = (int *) malloc(2 * sizeof *ej[i]), eo[i] = 0; line = 1; for (h = 0; h < n - 1; h++) { scanf("%d%d", &i, &j), i--, j--; if (i + 1 != j) line = 0; append(i, j), append(j, i); } dfs(-1, 0, 0); if (line) { scanf("%d", &m); memset(jj, -1, n * sizeof *jj); while (m--) { scanf("%d%d", &i, &j), i--, j--; jj[i] = j; } yes = 1; for (i = 0, j = -1; i < n; i++) if (jj[i] != -1) { if (j >= jj[i]) { yes = 0; break; } j = jj[i]; } printf(yes ? "Yes\n" : "No\n"); } else { memset(bb, 0, n * sizeof *bb); scanf("%d", &m); for (h = 0; h < m; h++) { scanf("%d%d", &ii[h], &jj[h]), ii[h]--, jj[h]--; i = ii[h], j = jj[h]; while (i != j) if (dd[i] > dd[j]) bb[i] |= 1 << h, i = pp[i]; else bb[j] |= 1 << h, j = pp[j]; bb[i] |= 1 << h; } printf(((bb[ii[0]] & 1 << 1) != 0 || (bb[jj[1]] & 1 << 0) != 0) && ((bb[ii[1]] & 1 << 0) != 0 || (bb[jj[0]] & 1 << 1) != 0) ? "No\n" : "Yes\n"); } } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

jail.c: In function 'append':
jail.c:12:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   12 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
jail.c: In function 'main':
jail.c:34:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  scanf("%d", &t);
      |  ^~~~~~~~~~~~~~~
jail.c:40:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d", &n);
      |   ^~~~~~~~~~~~~~~
jail.c:45:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |    scanf("%d%d", &i, &j), i--, j--;
      |    ^~~~~~~~~~~~~~~~~~~~~
jail.c:52:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |    scanf("%d", &m);
      |    ^~~~~~~~~~~~~~~
jail.c:55:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     scanf("%d%d", &i, &j), i--, j--;
      |     ^~~~~~~~~~~~~~~~~~~~~
jail.c:70:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |    scanf("%d", &m);
      |    ^~~~~~~~~~~~~~~
jail.c:72:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     scanf("%d%d", &ii[h], &jj[h]), ii[h]--, jj[h]--;
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...