My code
// Task 3: Determine the mininum number of assistance cars required
public int minNumAssistanceCars() {
// Add your code here to compute and return the minimum number of assistance cars required for this map
boolean [] visited = new boolean [numPlaces()];
int Nodes = numPlaces();
int count = 0;
for (int i = 0; i<numPlaces();i++){
if(!visited[i]){
count++;
DepthFirstSearch(getPlace(i),places,visited,Nodes);
}
}
return count;
}
private void DepthFirstSearch(Vertex Node, ArrayList<Vertex> Stack, boolean[] visited, int Nodes){
visited[Node.getIndex()] = true;
for (int i = 0; i < Nodes;i++){
if((Stack.get(Node.getIndex())).get(i) == 1 && !visited[i]){
DepthFirstSearch(Node,Stack,visited,i);
}
}
}```
the code i am referencing
```java
class Solution {
private static void dfs(ArrayList<ArrayList<Integer>> adj,boolean[] visited,int src,int v){
visited[src]=true;
for(int i=0;i<v;i++){
if(adj.get(src).get(i)==1 && !visited[i]){
dfs(adj,visited,i,v);
}
}
}
static int numProvinces(ArrayList<ArrayList<Integer>> adj, int V) {
// code here
// crete graph
int count=0;
boolean[] visited=new boolean[V];
for(int i=0;i<V;i++){
if(!visited[i]){
count++;
dfs(adj,visited,i,V);
}
}
return count;
}
};```