import java.util.ArrayList;
public class Solution {
public static int[][] printAdjacency(int n, int m, int[][] edges) {
// Write your code here.
ArrayList<Integer>[] adjList = new ArrayList[n];
// create graph for the n vertex
for(int i = 0; i < n; i++){
adjList[i] = new ArrayList<>();
}
// connect vertex with edges
for(int i = 0; i < m; i++){
int u = edges[i][0];
int v = edges[i][1];
adjList[u].add(v);
adjList[v].add(u);
}
// prepare output matrix
int[][] mat = new int[n][];
for(int i = 0; i < n; i++){
// add row number to the head of the list
adjList[i].add(0,i);
int k = adjList[i].size();
// initialized array for each list of rows
mat[i] = new int[k];
// intialize values in the corresponding row&col coordinate
for(int j = 0;j < k; j++){
mat[i][j] = adjList[i].get(j);
}
}
return mat;
}
}