Casur_Ras's blog

By Casur_Ras, history, 8 hours ago, In English

The key difference between Breadth-First Search (BFS) and Dijkstra's algorithm is that BFS assumes all edge weights are equal, typically set to 1. In contrast, Dijkstra's algorithm can accommodate edges with varying weights. I aim to develop a unified algorithm that combines both BFS and Dijkstra's approaches. My goal is to create an algorithm that can operate with either a queue or a priority queue, rather than using both simultaneously. Here’s my initial attempt: (Also I'm trying to make them both work with either queue or pq not both already have the algorithm with both in use ) map<int,vector> aj; map<int,int> dist,dumbells; set bwise; queue had; bool istheprobdij=0; void changerfordij(int w) { for(int n:aj[w]) { if(bwise.find(n)==bwise.end())had.push(n),bwise.insert(n),dist[n]=dist[w]+dumbells[n]; else { dist[n]=min(dist[n],dist[w]+dumbells[n]); } } } void changer(int w) { for(int n:aj[w]) { if(bwise.find(n)==bwise.end())had.push(n),bwise.insert(n),dist[w]=dist[n]+1; } } void csrsbfs(int a) { had.push(a); if(!istheprobdij)dist[a]=0; else dist[a]=dumbells[a]; while(!had.empty()) { long long j=had.front(); had.pop(); cout<<j<<' '; if(!istheprobdij)changer(j); else changerfordij(j); } }

  • Vote: I like it
  • -16
  • Vote: I do not like it

»
8 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

here's the normal code https://pastebin.com/GsP0z99J