# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1009177 | ivopav | Special graph (IZhO13_specialg) | C++17 | 1063 ms | 2256 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |