import java.util.*;
public class q48 {
public static LinkedList<Integer> adjacency[];
public q48(int v)
{
adjacency = new LinkedList[v];
for(int i=0; i<v; i++)
{
adjacency[i]=new LinkedList<Integer>();
}
}
public static void implementgraph(int s,int d)
{
adjacency[s].add(d);
adjacency[d].add(s);
}
public static void bfs(int source)
{
boolean visited_nodes[] = new boolean[adjacency.length];
int parent_nodes[] = new int[adjacency.length];
Queue<Integer> q= new LinkedList<>();
q.add(source);
visited_nodes[source]=true;
parent_nodes[source]=-1;
while(!q.isEmpty())
{
int p = q.poll();
System.out.println(p);
for(int i:adjacency[p])
{
if(visited_nodes[i] != true)
{
visited_nodes[i] = true;
q.add(i);
parent_nodes[i]=p;
}
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter vertice and edges : ");
int v = sc.nextInt();
int e = sc.nextInt();
q48 g= new q48(v);
System.out.println("Enter the edges : ");
for(int i=0; i<e; i++)
{
int s = sc.nextInt();
int d = sc.nextInt();
implementgraph(s,d);
}
System.out.println("Enter source node : ");
int source = sc.nextInt();
bfs(source);
}
}
when I compile same code in VSCode then its working perfectly but when I compile this code with Command prompt gave error