1 test case not passing. KIndly help

import java.io.;
import java.math.
;
import java.security.;
import java.text.
;
import java.util.;
import java.util.concurrent.
;
import java.util.regex.*;

public class Solution {

// Complete the findShortest function below.

/*
 * For the unweighted graph, <name>:
 *
 * 1. The number of nodes is <name>Nodes.
 * 2. The number of edges is <name>Edges.
 * 3. An edge exists between <name>From[i] to <name>To[i].
 *
 */
static int findShortest(int graphNodes, int[] graphFrom, int[] graphTo, long[] ids, int val) {
    // solve here
    ArrayList<ArrayList<Integer>> al = new ArrayList<>();

    for(int i=0;i<graphNodes;i++)
    {
        al.add(new ArrayList<Integer>());
    }

    for(int i=0;i<graphFrom.length;i++)
    {
        al.get(graphFrom[i]-1).add(graphTo[i]-1);
        al.get(graphTo[i]-1).add(graphFrom[i]-1);
    }

    boolean[] visited = new boolean[graphNodes];
    int start =0;
    for(int i=0;i<ids.length;i++)
    {
        if(val==ids[i])
        {
            start =i;
            break;
        }
    }

    Queue<Integer> q = new LinkedList<>();
    q.add(start);

    visited[start]= true;
    int[] dist = new int[graphNodes];

    while(!q.isEmpty())
    {
        int u = q.poll();
        for(int v : al.get(u))
        {
            if(visited[v]==false)
            {
                visited[v]=true;
                q.add(v);
                dist[v] = dist[u]+1;
               
            }
        }
      
    }

    int min = Integer.MAX_VALUE;

    for(int i=start+1;i<graphNodes;i++)
    {
        if(val == ids[i])
        {
            min = Math.min(min,dist[i]);
        }
    }
    if(min==Integer.MAX_VALUE)
    {
        return -1;
    }
    else
    {
        return min;
    }

}

private static final Scanner scanner = new Scanner(System.in);

public static void main(String[] args) throws IOException {
    BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

    String[] graphNodesEdges = scanner.nextLine().split(" ");
    int graphNodes = Integer.parseInt(graphNodesEdges[0].trim());
    int graphEdges = Integer.parseInt(graphNodesEdges[1].trim());

    int[] graphFrom = new int[graphEdges];
    int[] graphTo = new int[graphEdges];

    for (int i = 0; i < graphEdges; i++) {
        String[] graphFromTo = scanner.nextLine().split(" ");
        graphFrom[i] = Integer.parseInt(graphFromTo[0].trim());
        graphTo[i] = Integer.parseInt(graphFromTo[1].trim());
    }

    long[] ids = new long[graphNodes];

    String[] idsItems = scanner.nextLine().split(" ");
    scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

    for (int i = 0; i < graphNodes; i++) {
        long idsItem = Long.parseLong(idsItems[i]);
        ids[i] = idsItem;
    }

    int val = scanner.nextInt();
    scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

    int ans = findShortest(graphNodes, graphFrom, graphTo, ids, val);

    bufferedWriter.write(String.valueOf(ans));
    bufferedWriter.newLine();

    bufferedWriter.close();

    scanner.close();
}

}

@sarveshbibhuty your code gives -1 for huge test cases.try and correct that