답안 #1009177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1009177 2024-06-27T09:42:57 Z ivopav 특수한 그래프 (IZhO13_specialg) C++17
0 / 100
1000 ms 2256 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> slje={};
    for (int i=0;i<n;i++){
        int unos;
        cin >> unos;
        slje.push_back(unos-1);
    }
    int q;
    cin >> q;
    vector<int> zad(n,-1);
    for (int i=0;i<q;i++){
        int typ;
        cin >> typ;
        if (typ==1){
            int unos;
            cin >> unos;
            slje[--unos]=-1;
        }
        else {
            int unos;
            int unos2;
            cin >> unos >> unos2;
            int rje=0;
            --unos;
            --unos2;
            while (unos!=unos2){
                if (zad[unos]==i || slje[unos]==-1){
                    rje=-1;
                    break;
                }
                zad[unos]=i;
                rje++;
                unos=slje[unos];
            }
            cout << rje << " \n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 352 KB Output is correct
6 Correct 26 ms 736 KB Output is correct
7 Correct 32 ms 604 KB Output is correct
8 Correct 31 ms 600 KB Output is correct
9 Correct 24 ms 604 KB Output is correct
10 Correct 28 ms 600 KB Output is correct
11 Execution timed out 1063 ms 2256 KB Time limit exceeded
12 Halted 0 ms 0 KB -