Siddharth and Permutations

my code is failing on test case 1 tell we where i am going wrong?
here is my code—
#include <bits/stdc++.h>
using namespace std;

int n,ans[500001],arr[500001];
int indegree[500001]={-1};
int visited[500001];
int put;
int last;
void addEdge(vector adj[], int u, int v)
{
adj[u].push_back(v);

}
void topologicalsort(vector v[])
{
priority_queueq;

for(int i=1;i<=n;i++)
{
    if(indegree[i]==0)  {
         q.push(i);  
		 visited[i]=true; }
}
while(!q.empty())
{
    int i = q.top();   
    q.pop();
      
    for(int j=0;j<v[i].size();j++)
    {
        if(!visited[v[i][j]])
        {
            indegree[v[i][j]] --;
            if(indegree[v[i][j]]==0)
            {
            	  
                  ans[v[i][j]]=last;
                  last--;
                  q.push(v[i][j]); 
                  visited[v[i][j]] = true;
            }
        }
    }
}

}

int main() {
cin>>n;
for(int i=1;i<=n;i++) cin>>arr[i];
vector v[n+1];

int rev=n;
put=n;
indegree[500001]={0};
for(int i=1;i<=n;i++)
{
visited[i]=0;
if(arr[i]==-1)
{
ans[i] = rev;
rev–;
last=rev;
indegree[i]=0;
}
else{
addEdge(v,arr[i],i);
indegree[i]++;
}

}

topologicalsort(v);

for(int i=1;i<=n;i++)
cout<<ans[i]<<" ";
}

Hey!
Your code is absolutely fine. Its working fine for both the test cases, i have checked.
There might be some fault from our side, please ignore it for the time.
You may close the thread.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.