제출 #1009177

#제출 시각아이디문제언어결과실행 시간메모리
1009177ivopav특수한 그래프 (IZhO13_specialg)C++17
0 / 100
1063 ms2256 KiB
#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";
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...