Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<int> g[n];
- int depth[n];
- void bfs(int from){
- fill(depth,depth+n, inf);
- depth[0] = 0;
- queue<pair<int,int> > q;
- q.push({from,0});
- while(q.size()){
- auto [nxtv, nxtw] = q.front();
- q.pop();
- if(depth[nxtv] < nxtw) continue;
- for(int v : g[nxtv]){
- if(depth[nxtv] + 1 < depth[v]){
- depth[v] = depth[nxtv] + 1;
- q.push({v,depth[v]});
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement