답안 #81640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81640 2018-10-25T17:13:35 Z inom 학교 설립 (IZhO13_school) C++14
0 / 100
2000 ms 37448 KB
#include<bits/stdc++.h>

#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define int long long
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define in freopen("specialg.in", "r", stdin);
#define out freopen("specialg.out", "w", stdout);

using namespace std;
/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma warning(disable : 4996)
*/
const int N = 500100;
const int INF = 1e15;

int TN = 1;

int n, m;
vector<int> g[N];

int get(int x, int y) {
    int d[N], us[N];
    for (int i = 1; i <= n; i++) {
        d[i] = -1; us[i] = 0;
    }
    queue<int> q; q.push(x);
    d[x] = 0; us[x] = true;
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (auto i: g[v]) {
            if (!us[i]) {
                d[i] = d[v] + 1;
                us[i] = true; q.push(i);
            }
        }
    }
    return d[y];
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        if (!x) {
            continue;
        }
        g[i].pb(x);
    }
    cin >> m;
    while (m--) {
        int t;
        cin >> t;
        if (t == 1) {
            int x; cin >> x;
            g[x].clear();
        }
        else {
            int x, y; cin >> x >> y;
            cout << get(x, y) << "\n";
        }
    }
    return;
}

signed main() {
    // ios_base::sync_with_stdio(0);
    // in; out; // cin >> TN;
    while (TN--) solve();
    return 0;
 }
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 12124 KB Output isn't correct
2 Incorrect 11 ms 12160 KB Output isn't correct
3 Incorrect 12 ms 12208 KB Output isn't correct
4 Incorrect 11 ms 12292 KB Output isn't correct
5 Incorrect 15 ms 12464 KB Output isn't correct
6 Incorrect 20 ms 12596 KB Output isn't correct
7 Incorrect 238 ms 13016 KB Output isn't correct
8 Incorrect 401 ms 13260 KB Output isn't correct
9 Incorrect 385 ms 13260 KB Output isn't correct
10 Incorrect 467 ms 13440 KB Output isn't correct
11 Incorrect 400 ms 13484 KB Output isn't correct
12 Incorrect 266 ms 13484 KB Output isn't correct
13 Execution timed out 2056 ms 15112 KB Time limit exceeded
14 Execution timed out 2056 ms 17804 KB Time limit exceeded
15 Execution timed out 2064 ms 22716 KB Time limit exceeded
16 Execution timed out 2059 ms 24892 KB Time limit exceeded
17 Execution timed out 2065 ms 28268 KB Time limit exceeded
18 Execution timed out 2068 ms 30696 KB Time limit exceeded
19 Execution timed out 2063 ms 33552 KB Time limit exceeded
20 Execution timed out 2073 ms 37448 KB Time limit exceeded