We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3930a1c commit 3ea2a4bCopy full SHA for 3ea2a4b
graph_theory/graph_traversal/breadth_first_search.cpp
@@ -23,12 +23,24 @@ void _clear() {
23
void BFS(int src) {
24
memset(dis, 0x3f, sizeof(dis[0]) * (n + 2));
25
memset(Par, -1, sizeof(Par[0]) * (n + 2));
26
- wdwadfppfnqkpfigikw;
27
- lgfdjklsaigrkf,sdapgkz
28
- }
+
+ queue <int> q;
+ q.push(src);
29
+ dis[src] = 0;
30
31
+ int u;
32
+ while(q.size()) {
33
+ u = q.front(); q.pop();
34
+ for(int i = Head[u]; i; i = Next[i])
35
+ if(dis[To[i]] == oo) {
36
+ dis[To[i]] = dis[u] + 1;
37
+ Par[To[i]] = u;
38
+ q.push(To[i]);
39
+ }
40
41
}
42
-int main()
43
+int main()
44
{
45
cin >> n >> m >> st >> tr;
46
while(m--) {
@@ -40,4 +52,3 @@ int main()
52
BFS(st);
53
cout << dis[tr] << endl;
54
-
0 commit comments