답안 #440700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440700 2021-07-02T18:11:05 Z parsabahrami 학교 설립 (IZhO13_school) C++17
0 / 100
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

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);
      |             ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 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