### nrg_aceu's blog

By nrg_aceu, history, 4 weeks ago, i read cp algorithm and understand bfs theory.when it comes to implementation i cant. see this code https://pastebin.com/5RtDSMMW this is literally copying yet its still wrong idk whats wrong.pls help Comments (18)
 » pls help.im tired of asking someone in discord since theyll just ignore me.i really want to learn bfs and i cant.
•  » »
•  » » » that book is the worst.it left me confused at the implementation like what am i suppose to write in int main? whenever i tried to see the implementation example it just wont print anything.
•  » » » » 4 weeks ago, # ^ | ← Rev. 2 →   If you can't implement bfs by your own in main function despite having the bfs structure ready, then you have lack of understanding of bfs, that's not the fault of the book
•  » » » » » what i dont understand is actually the variations.some use vector for storing adj list for bfs and some use vector pair.i was confused since in the article i read it uses vector vector and what i elarn from my teacher is vector pair.this also applies to that book.the standards are different
•  » » » » » » I don't know how the vector of pairs implementation works, but vector of vectors is used because for a vector with index $i$, all the values in that vector are neighbours of $i$. For example if 1,2,3 are stored in vector adj, then nodes 1,2,3 are neighbours of node 0. This way after processing node 0, you can push it's neighbours (1,2,3) in the queue for processing.
•  » » » » » » » Vector of pairs is basically adjacency matrix
•  » » » » » » then don't use it.to be honest, you don't need bfs to get to pupil
•  » » » » » » » even you don't need bfs to get to specialist
•  » » » » You can use GreeksForGeeks for better understanding.
•  » » » » » Yes nrg_aceu go there
•  » » » » » it uses OOP.i dont udnerstand OOP.
• »
»
»
»
»
»
4 weeks ago, # ^ |
Rev. 2

// A Quick implementation of BFS using // vectors and queue

# define pb push_back

using namespace std;

vector v; vector<vector > g;

void edge(int a, int b) { g[a].pb(b);

// for undirected graph add this line
// g[b].pb(a);


}

void bfs(int u) { queue q;

q.push(u);
v[u] = true;

while (!q.empty()) {

int f = q.front();
q.pop();

cout << f << " ";

// Enqueue all adjacent of f and mark them visited
for (auto i = g[f].begin(); i != g[f].end(); i++) {
if (!v[*i]) {
q.push(*i);
v[*i] = true;
}
}
}


}

// Driver code int main() { int n, e; cin >> n >> e;

v.assign(n, false);
g.assign(n, vector<int>());

int a, b;
for (int i = 0; i < e; i++) {
cin >> a >> b;
edge(a, b);
}

for (int i = 0; i < n; i++) {
if (!v[i])
bfs(i);
}

return 0;


}

Where the fuck do you find oop here?

•  » » Search CodeNCode graph playlist on YT
•  » » refer codencode utube channel and study graphs from there. If u find it useful then thank me later
 » I would suggest you to watch the amazing graph series by striver_79 He has explained each and every concept very well. Here is the link to the playlist: Striver's Graph Series
 » 4 weeks ago, # | ← Rev. 2 →   do you even understand how bfs works?
 » Go through the graph theory playlist by William Fiset. Here's the link it has neat visualization and implementation as well. https://www.youtube.com/playlist?list=PLDV1Zeh2NRsDGO4--qE8yH72HFL1Km93P