Skip to content

Commit 580fc60

Browse files
committed
Initial Commit
1 parent 9774e6d commit 580fc60

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

graph-theory/dfs_search.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ void dfs_search(vector<vector<int>> &graph, int vertex, vector<bool> &visited)
2323
dfs_search(graph, u, visited); // Make a dfs call if the current vertex is not visited
2424
}
2525
}
26-
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
***************************
3+
* *
4+
* Author: Swaraj Deep *
5+
* *
6+
***************************
7+
*/
8+
// Single Source Shortest Path on trees
9+
10+
#include <iostream>
11+
#include <vector>
12+
13+
using namespace std;
14+
15+
void dfs_search(vector<vector<int>> &graph, int vertex, vector<bool> &visited, int dist, vector<int> &s_distance)
16+
{
17+
visited[vertex] = true;
18+
s_distance[vertex] = dist;
19+
for (int u : graph[vertex])
20+
{
21+
if (!visited[u])
22+
{
23+
dfs_search(graph, u, visited, s_distance[vertex] + 1, s_distance);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)