답안 #81639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81639 2018-10-25T17:11:44 Z inom 특수한 그래프 (IZhO13_specialg) C++14
0 / 100
1000 ms 19260 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("notation.in", "r", stdin);
#define out freopen("notation.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;
 }

Compilation message

specialg.cpp:21:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable : 4996)
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 12152 KB Output is correct
2 Correct 25 ms 12332 KB Output is correct
3 Correct 27 ms 12412 KB Output is correct
4 Correct 41 ms 12520 KB Output is correct
5 Correct 27 ms 12520 KB Output is correct
6 Correct 179 ms 12936 KB Output is correct
7 Correct 170 ms 13108 KB Output is correct
8 Correct 194 ms 13492 KB Output is correct
9 Correct 172 ms 13832 KB Output is correct
10 Correct 200 ms 14108 KB Output is correct
11 Execution timed out 1084 ms 19260 KB Time limit exceeded
12 Halted 0 ms 0 KB -