Help me in solving REVERSE problem

My issue

failing in only one testcase dont know why

My code

#include <bits/stdc++.h>
using namespace std;


int bfs(int n, vector<int>&level,vector<vector<int>>g[] ){
    deque<int>q;
    q.push_back(1);
    level[1]=0;
    while(!q.empty()){
        int it=q.front();
        q.pop_front();
        for(auto child :g[it]){
            int v=child[0];
            int wt=child[1];
            if(level[it]+wt<level[v]){
                level[v]=level[it]+wt;
                if(wt==0)q.push_front(v);
                else q.push_back(v);
            }
        }
    }
    return level[n]==1e9?-1:level[n];
}

int main() {
	// your code goes here
	int n,m;
	cin>>n>>m;
	int inf=1e9;
	vector<vector<int>>g[n+1];
	vector<int>level(n+1,inf);
	for(int i=1;i<=n;i++){
	    int x,y;
	    cin>>x>>y;
	    if(x==y)continue;
	    g[x].push_back({y,0});
	    g[y].push_back({x,1});
	}
	cout<< bfs(n,level,g)<<endl;
	return 0;
}



Problem Link: REVERSE Problem - CodeChef