Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Function of a graph class with 2-dimensional vector acting as an edge net
- // Edges are assumed to be undirected and unweighted
- void BFS(int src)
- {
- std::vector<int> visited(size(), false);
- visited[src] = true;
- std::queue<int> Q;
- Q.push(src);
- while(!Q.empty())
- {
- int from = Q.front();
- Q.pop();
- for(int to : edges[from])
- {
- if(!visited[to])
- {
- visited[to] = true;
- Q.push(to);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement