1//just push all the sources into the queue and perform simple bfs
2vector<int> sources;
3
4unordered_map<int,bool> vis;
5unordered_map<int,int> dist;
6queue<int> q;
7
8for(int i = 0;i<sources.size();i++){
9 vis[sources[i]] = true;
10 dist[sources[i]] = 0;
11 q.push(sources[i]);
12}
13// then proceed as usual
14
15
16while(!q.empty()){
17 int p = q.front();
18 q.pop();
19
20 for(int i = 0;i< g[p].size();i++){
21 if(!vis[g[p][i]]){
22 vis[g[p][i]] = true;
23 dist[g[p][i]] = dist[p] + 1;
24 q.push(g[p][i]);
25 }
26 }
27}