Language: C++

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P; 

const int maxn = 100010;

int n,m,s,u,v;
int dis[maxn],vis[maxn];

priority_queue<P,vector<P>,greater<P> > q;

int h[maxn],size;
struct E{
	int to , next;
	ll cost;
}e[maxn*2];
void add(int u,int v,ll w){
	e[++size].to = v;
	e[size].cost = w;
	e[size].next = h[u];
	h[u]=size;
}

void dij(){
	memset(dis,0x3f,sizeof(dis));
	dis[1]=0;
	q.push(P(0,1));
	
	while(!q.empty()){
		int u = q.top().second; q.pop();
		
		if(vis[u]) continue;
		vis[u]=1;
		
		for(int i = h[u];i != -1;i = e[i].next){
			int v = e[i].to;
			if(dis[v] > dis[u] + e[i].cost){
				dis[v] = dis[u] + e[i].cost;
				q.push(P(dis[v],v));
			}
		}
	}
	
}

ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }

int main(){
	memset(h,-1,sizeof(h));
	memset(vis,0,sizeof(vis));
	n=read();
	for(int i = 1;i <= n;i++){
		v=read();
		add(i,v,1);
	}

	dij();

	if((h[2] == -1)||vis[2] == 0){
		printf("-1\n");
		return 0; 
	}
	
	printf("%d\n",dis[2]);
	
	return 0;
}

Compiler output:
a.cc: In function 'void add(int, int, ll)':
a.cc:25:13: error: reference to 'size' is ambiguous
   25 |         e[++size].to = v;
      |             ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:4:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:19:13: note:                 'int size'
   19 | int h[maxn],size;
      |             ^~~~
a.cc:26:11: error: reference to 'size' is ambiguous
   26 |         e[size].cost = w;
      |           ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:19:13: note:                 'int size'
   19 | int h[maxn],size;
      |             ^~~~
a.cc:27:11: error: reference to 'size' is ambiguous
   27 |         e[size].next = h[u];
      |           ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:19:13: note:                 'int size'
   19 | int h[maxn],size;
      |             ^~~~
a.cc:28:14: error: reference to 'size' is ambiguous
   28 |         h[u]=size;
      |              ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:19:13: note:                 'int size'
   19 | int h[maxn],size;
      |             ^~~~