제출 #1222698

#제출 시각아이디문제언어결과실행 시간메모리
1222698sleepntsheepPrize (CEOI22_prize)C++17
0 / 100
148 ms7428 KiB
#include <stdio.h> #define N 200000 int n, k, q, t, p[N], dfn[N], dfc, nfd[N], fa[N], hd[N], e[N * 2] , Ln[N * 2], ii, rt, hld[N], lv[N], dis[N], sz[N]; void add(int u, int v) { ++ii; e[ii] = v, Ln[ii] = hd[u]; hd[u] = ii; } void dfs(int u) { sz[u] = 1; for (int v, j = hd[u]; j; j = Ln[j]) { v = e[j]; lv[v] = lv[u] + 1; dfs(v); sz[u] += sz[v]; if (sz[v] > sz[e[hd[u]]]) e[j] = e[hd[u]], e[hd[u]] = v; } } void dfs2(int u) { nfd[dfn[u] = dfc++] = u; for (int v, j = hd[u]; j; j = Ln[j]) { v = e[j]; hld[v] = j == hd[u] ? hld[u]: v; dfs2(v); } } int lca(int u, int v) { while (hld[u] != hld[v]) { if (lv[hld[u]] > lv[hld[v]]) u = fa[hld[u]]; else v = fa[hld[v]]; } return dfn[u] < dfn[v] ? u: v; } int main() { scanf("%d%d%d%d", &n, &k, &q, &t); for (int i = 0; i < n; ++i) { scanf("%d", &fa[i]); if (fa[i] == -1) rt = i; else add(--fa[i], i); } for (int i = 0; i < n; ++i) scanf("%*d"); return 0; fa[rt] = rt; hld[rt] = rt; dfs(rt); dfs2(rt); return 0; for (int i = 0; i < k; ++i) printf("%d ", 1 + nfd[i]); puts(""); for (int i = 1; i <= q; ++i) printf("? %d %d\n", 1 + rt, 1 + nfd[i]); puts("!"); fflush(stdout); for (int i = 1; i <= q; ++i) scanf("%*d%d%*d%*d\n", dis + nfd[i]); for (int i = 0; i < t; ++i) { int u, v; scanf("%d%d", &u, &v), --u, --v; int x = dis[u] + dis[v] - 2 * dis[lca(u, v)]; printf("%d %d\n", x, x); } fflush(stdout); return 0; }

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

Main.cpp: In function 'int main()':
Main.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%d%d%d%d", &n, &k, &q, &t);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |                 scanf("%d", &fa[i]);
      |                 ~~~~~^~~~~~~~~~~~~~
Main.cpp:55:42: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         for (int i = 0; i < n; ++i) scanf("%*d");
      |                                     ~~~~~^~~~~~~
Main.cpp:72:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |                 scanf("%*d%d%*d%*d\n", dis + nfd[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:76:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |                 scanf("%d%d", &u, &v), --u, --v;
      |                 ~~~~~^~~~~~~~~~~~~~~~
#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...