public void bfs(int v) {
        boolean[] visited = new boolean[n];
        Queue<Integer> queue = new LinkedList<Integer>();
        queue.offer(v);
        while(!queue.isEmpty()){
            int n = queue.poll();
            visited[n] = true;
            System.out.print(n + " ");
            for(int num : adj[n]){
                if(!visited[num]){
                    queue.offer(num);
                }
            }
        }
    }