# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
440700 | 2021-07-02T18:11:05 Z | parsabahrami | Schools (IZhO13_school) | C++17 | 2000 ms | 63876 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 47180 KB | Output isn't correct |
2 | Incorrect | 26 ms | 47280 KB | Output isn't correct |
3 | Incorrect | 30 ms | 47280 KB | Output isn't correct |
4 | Incorrect | 29 ms | 47304 KB | Output isn't correct |
5 | Incorrect | 31 ms | 47340 KB | Output isn't correct |
6 | Incorrect | 33 ms | 47388 KB | Output isn't correct |
7 | Incorrect | 71 ms | 47636 KB | Output isn't correct |
8 | Incorrect | 116 ms | 47564 KB | Output isn't correct |
9 | Incorrect | 99 ms | 47756 KB | Output isn't correct |
10 | Incorrect | 115 ms | 47684 KB | Output isn't correct |
11 | Incorrect | 107 ms | 47676 KB | Output isn't correct |
12 | Incorrect | 74 ms | 47584 KB | Output isn't correct |
13 | Incorrect | 730 ms | 49308 KB | Output isn't correct |
14 | Incorrect | 1386 ms | 51720 KB | Output isn't correct |
15 | Execution timed out | 2082 ms | 56000 KB | Time limit exceeded |
16 | Execution timed out | 2073 ms | 57236 KB | Time limit exceeded |
17 | Execution timed out | 2085 ms | 59264 KB | Time limit exceeded |
18 | Execution timed out | 2072 ms | 60644 KB | Time limit exceeded |
19 | Execution timed out | 2085 ms | 61612 KB | Time limit exceeded |
20 | Execution timed out | 2093 ms | 63876 KB | Time limit exceeded |