Submission #1235343

#TimeUsernameProblemLanguageResultExecution timeMemory
1235343spetrPrize (CEOI22_prize)C++20
Compilation error
0 ms0 KiB
#include <stdio.h> using namespace std; #define N 1000000 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"); fa[rt] = rt; hld[rt] = rt; dfs(rt); dfs2(rt); for (int i = 0; i < k; ++i) printf("%d ", 1 + nfd[i]); puts(""); fflush(stdout); 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]); static int q1[N], q2[N]; for (int i = 0; i < t; ++i) cin >> q1[i]>> q2[i]; for (int i = 0; i < t; ++i) { int u, v; u = q1[i] - 1, v = q2[i] - 1; int x = dis[u] + dis[v] - 2 * dis[lca(u, v)]; cout << x << " " << x << "\n"; } fflush(stdout); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:76:17: error: 'cin' was not declared in this scope
   76 |                 cin >> q1[i]>> q2[i];
      |                 ^~~
Main.cpp:2:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    1 | #include <stdio.h>
  +++ |+#include <iostream>
    2 | using namespace std;
Main.cpp:82:17: error: 'cout' was not declared in this scope
   82 |                 cout << x << " " << x << "\n";
      |                 ^~~~
Main.cpp:82:17: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
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:71:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |                 scanf("%*d%d%*d%*d\n", dis + nfd[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~