adj for each of the n nodes.(i, j) and if haveSameCategory(i, j) returns true, add an undirected edge between i and j in adj.vis with all false values and a variable components as 0.i:
a. If vis[i] is false, perform DFS starting from node i.
b. In each DFS call, mark the node as visited and recursively visit all unvisited adjacent nodes.
c. Increment components each time a new DFS is initiated.components.