Submission #339429

#TimeUsernameProblemLanguageResultExecution timeMemory
339429beksultan04Special graph (IZhO13_specialg)C++14
0 / 100
1077 ms1824 KiB
#include <bits/stdc++.h> using namespace std; //#define int long long #define pii pair<int,int> #define OK puts("OK"); #define NO puts("NO"); #define YES puts("YES"); #define fr first #define sc second #define ret return #define scan1(a) scanf("%lld",&a); #define scan2(a,b) scanf("%lld %lld",&a, &b); #define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c); #define all(s) s.begin(),s.end() #define allr(s) s.rbegin(),s.rend() #define pb push_back #define sz(v) (int)v.size() #define endi puts(""); #define eps 1e-15 const int N = 1e5+12,INF=1e9+7; int q[N]; bool vis[N]; main(){ int n,i,j,m; cin>>n; for (i=1;i<=n;++i){ cin>>q[i]; } cin>>m; while (m--){ int t; cin>>t; if (t==1){ int x; cin>>x; q[x] = 0; } else { int x,y; cin>>x>>y; int ans=0; priority_queue <int> t; while (q[x] != 0 && x != y){ if (vis[x])break; vis[x]=1; t.push(x); x = q[x]; ans ++; } while (!t.empty()){ vis[t.top()]=0; t.pop(); } if (x != y )ans =-1; cout <<ans<<'\n'; } } }

Compilation message (stderr)

specialg.cpp:23:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   23 | main(){
      |      ^
specialg.cpp: In function 'int main()':
specialg.cpp:24:13: warning: unused variable 'j' [-Wunused-variable]
   24 |     int n,i,j,m;
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...