Submission #440700

#TimeUsernameProblemLanguageResultExecution timeMemory
440700parsabahramiSchools (IZhO13_school)C++17
0 / 100
2093 ms63876 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second const int N = 1e6 + 10, MOD = 1e9 + 7; set<int> adj[N]; int dp[N], nxt[N], n, q; void BFS(int st) { queue<int> Q; fill(dp, dp + n + 1, MOD); Q.push(st), dp[st] = 0; while (SZ(Q)) { int v = Q.front(); Q.pop(); for (int u : adj[v]) if (dp[u] > dp[v] + 1) dp[u] = dp[v] + 1, Q.push(u); } } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &nxt[i]); for (int i = 1; i <= n; i++) { if (nxt[i]) adj[i].insert(nxt[i]); } scanf("%d", &q); for (int i = 1; i <= q; i++) { int t, v, u; scanf("%d%d", &t, &v); if (t < 2) adj[v].erase(nxt[v]); else { scanf("%d", &u); BFS(v); printf("%d\n", dp[u] > n ? -1 : dp[u]); } } return 0; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
school.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d", &nxt[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
school.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
school.cpp:35:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         int t, v, u; scanf("%d%d", &t, &v);
      |                      ~~~~~^~~~~~~~~~~~~~~~
school.cpp:38:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |             scanf("%d", &u);
      |             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...