daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. BFS(G, s) {
  2.   double inf = std::numeric_limits<double>::infinity();
  3.   for (int i = 0; i < G.v.size(); i++) {
  4.     if(G.v[i] != s) {
  5.         G.v[i].color = "white";
  6.         G.v[i].d = inf;
  7.         G.v[i].parent = null;
  8.     }
  9.   }
  10.   s.color = "gray";
  11.   s.d = 0;
  12.   s.parent = null;
  13.   std::vector<Node> Q;
  14.   Enqueue(Q,s);
  15.   while (Q.size() > 0) {
  16.     Node u = Dequeue(Q);
  17.     std::vector<Node> AdjacentList = G.adj[u];
  18.     for (int i = 0; i < AdjacentList.size(); i++) {
  19.       if(AdjacentList[i].color == "white") {
  20.         AdjacentList[i].color = "gray";
  21.         AdjacentList[i].d = u.d + 1;
  22.         AdjacentList[i].parent = u;
  23.         Enqueue(Q, AdjacentList[i]);
  24.       }
  25.     }
  26.    
  27.   }
  28.  
  29. }
RAW Paste Data
Top