SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int main(){
  2.     d(V, INF);
  3.     d[s] = 0; // distance from source s to s is 0
  4.     queue<int> q;
  5.     q.push(s); // start from source
  6.     while (!q.empty()) {
  7.         int u = q.front();
  8.         q.pop(); // queue: layer by layer!
  9.         for (int j = 0; j < (int)AdjList[u].size(); j++) {
  10.             ii v = AdjList[u][j]; // for each neighbor of u
  11.             if (d[v.first] == INF) {
  12.                 // if v.first is unvisited + reachable
  13.                 d[v.first] = d[u] + 1; // make d[v.first] != INF to flag it
  14.                 q.push(v.first); // enqueue v.first for the next iteration
  15.             }
  16.         }
  17.     }
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top