Could someone please tell the mistake in my logic in using BFS to compute shortest distance of a node from a given starting node using adjacency list on an undirected graph?

```
void bfs(int s) {
dist[s] = 0;
queue<int> q; q.emplace(s);
while (!q.empty()) {
int u = q.front(); q.pop();
for (int i = 0; i < adj_list[u].size(); ++i) {
if (dist[adj_list[u][i]] == -1) {
dist[adj_list[u][i]] = 1 + dist[u];
q.emplace(adj_list[u][i]);
}
}
}
```

}

All distances are set to -1 before starting this algorithm.