MCPcopy Create free account
hub / github.com/Jonathan-Uy/CSES-Solutions / bfs

Function bfs

String Algorithms/Substring Distribution.cpp:53–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53void bfs(int s = 0){
54 queue<int> Q;
55 vis[s] = true;
56 dist[s] = 0;
57 Q.push(s);
58 while(!Q.empty()){
59 int u = Q.front();
60 Q.pop();
61 ans[dist[u]]++;
62 ans[node[u].len+1]--;
63 for(const auto& [c, v] : node[u].nxt){
64 if(!vis[v]){
65 dist[v] = dist[u]+1;
66 vis[v] = true;
67 Q.push(v);
68 }
69 }
70 }
71}
72
73int main(){
74 scanf(" %s", S);

Callers 1

mainFunction · 0.70

Calls 2

emptyMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected