2 solutions

  • 0
    @ 2025-6-22 14:15:41
    
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int a[55],n;cin>>n;a[0]=0;
    	for(int i=1;i<=n;i++){
    		cin>>a[i];
    	}
    	int m=1,p=a[n-1];
    	while(p!=1){
    		p=a[p-1];
    		m++;
    	}
    	cout<<m;
    	return 0;
    }
    ```
    
    
    ```
    • 0
      @ 2025-4-28 18:00:59
      #include<bits/stdc++.h>
      using namespace std;
      const int N=110;
      int a[N];
      int main()
      {
      	int n;
      	cin>>n;
      	for(int i=2;i<=n;i++)
      	{
      		int x;
      		cin>>x;
      		a[i]=a[x]+1;	
      	} 
      	cout<<a[n];
      	return 0;
      }
      
      
      • 1

      Information

      ID
      2371
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      1
      Tags
      (None)
      # Submissions
      17
      Accepted
      9
      Uploaded By