/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { { int n = sc.nextInt(); int m = sc.nextInt(); List<List<Integer>> adj = new ArrayList<>(); for(int i=0;i<=n; i++){ adj.add(new ArrayList<>()); } for(int i=0;i<m;i++){ int u = sc.nextInt(); int v = sc.nextInt(); adj.get(u).add(v); adj.get(v).add(u); } shoetestPathOfIthNodeFromSrc(adj,1); } public static void shoetestPathOfIthNodeFromSrc(List<List<Integer>> adj, int src){ int n = adj.size(); boolean visited[] = new boolean[n]; int level[] = new int [n]; int path[] = new int [n]; Queue<Integer> q = new LinkedList<>(); q.offer(src); level[src] = 0; path[src] = 1; visited[src] = true; while(!q.isEmpty()){ int cur = q.poll(); for(int x : adj.get(cur)){ if(!visited[x]){ q.add(x); level[x] = level[cur]+1; path[x] = path[cur]; visited[x]=true; }else{ if(level[cur]+1 == level[x]){ path[x] = path[x] + path[cur]; } } } } } }
10 11 1 2 1 3 1 4 4 8 3 6 2 5 8 9 6 7 5 10 9 10 7 10