Skip to content

Instantly share code, notes, and snippets.

@rohithpeddi
Created November 12, 2016 16:24
Show Gist options
  • Save rohithpeddi/5effc7f3b23328f4f09132b36d1bbe59 to your computer and use it in GitHub Desktop.
Save rohithpeddi/5effc7f3b23328f4f09132b36d1bbe59 to your computer and use it in GitHub Desktop.
DFS of EdgeWeightedGraph
static class DFS{
boolean[] marked;
public DFS(EdgeWeightedGraph G, int source){
marked = new boolean[G.noOfVertices];
dfs(G,source);
}
public void dfs(EdgeWeightedGraph G, int v){
marked[v] = true;
for(int w : G.getAdjVertices(v)){
if(!marked[w]){
dfs(G,w);
}
}
}
public boolean hasPathTo(int v){
return marked[v];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment