제출 #339418

#제출 시각아이디문제언어결과실행 시간메모리
339418tengiz05특수한 그래프 (IZhO13_specialg)C++17
0 / 100
1099 ms5992 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); #define all(x) (x).begin(), (x).end() #define pb push_back #define pii pair<int, int> #define ff first #define ss second #define PI acos(-1) #define ld long double template<class T> bool ckmin(T& a, const T& b) {return a>b? a=b, true:false;} template<class T> bool ckmax(T& a, const T& b) {return a<b? a=b, true:false;} const int mod = 1e9+7, N = 1e5+5; int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;} int n, m, k; int nex[N]; int ans[N]; bool black[N]; int dist; int looking_for; bool found; vector<bool> used; void dfs(int u, int d=0){ if(u == looking_for){ dist = d; found = true; return; } used[u] = true; if(!used[nex[u]])dfs(nex[u],d+1); } void solve(int test_case){ int i, j, numq; cin >> n; for(i=1;i<=n;i++){ cin >> nex[i]; } vector<tuple<int,int,int>> Q; cin >> numq; for(i=0;i<numq;i++){ int typ; cin >> typ; if(typ == 1){ int t; cin >> t; Q.pb(make_tuple(typ,t,0)); black[t] = true; }else { int l, r; cin >> l >> r; Q.pb(make_tuple(typ,l,r)); } } // reverse(all(Q)); for(i=0;i<numq;i++){ found = false; auto [typ, l, r] = Q[i]; if(typ == 2){ used.assign(n+1, 0); looking_for = r; dfs(l); if(found)ans[i] = dist; else ans[i] = -1; }else { nex[l] = 0; } } for(i=0;i<numq;i++){ if(get<0>(Q[i]) == 2)cout << ans[i] << '\n'; } return; } signed main(){ FASTIO; #define MULTITEST 0 #if MULTITEST int _T; cin >> _T; for(int T_CASE = 1; T_CASE <= _T; T_CASE++) solve(T_CASE); #else solve(1); #endif return 0; }

컴파일 시 표준 에러 (stderr) 메시지

specialg.cpp: In function 'void solve(long long int)':
specialg.cpp:34:9: warning: unused variable 'j' [-Wunused-variable]
   34 |  int i, j, numq;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...