masecla33

Untitled

May 4th, 2021
467
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <queue>
  2.  
  3.  
  4. #include <iostream>
  5. #include <fstream>
  6. #include <queue>
  7. #include <vector>
  8.  
  9. using namespace std;
  10.  
  11. vector <int> G[101];
  12. int n;
  13.  
  14. int queueEmu[101];
  15. int queueSize = 0;
  16.  
  17. void citire() {
  18.     ifstream fin("fis.in");
  19.     int x,y,m;
  20.     fin>>n>>m;
  21.     while(m--) {
  22.         fin>>x>>y;
  23.         G[x].push_back(y);
  24.         G[y].push_back(x);
  25.     }
  26. }
  27.  
  28. void bfs(int start) {
  29.     int viz[101]= {0};
  30.     queue <int> Q;
  31.     Q.push(start);
  32.     queueEmu[queueSize++]=start;
  33.  
  34.     viz[start]=1;
  35.     while(!Q.empty()) {
  36.         int curent=Q.front();
  37.         Q.pop();
  38.         queueSize--;
  39.  
  40.         cout<<"cr: "<<curent<<" \n";
  41.         for(int &x:G[curent])
  42.             if(viz[x]==0) {
  43.                 viz[x]=1;
  44.                 Q.push(x);
  45.                 queueEmu[queueSize++]=x;
  46.  
  47.                 cout<<"viz["<<x<<"]=1 ";
  48.                 cout<<"Q: {";
  49.                 for(int i=0;i<queueSize;i++){
  50.                     cout<<queueEmu[i];
  51.                     if(i!=queueSize-1)
  52.                         cout<<" ";
  53.                 }
  54.                 cout<<"}"<<endl;
  55.             }
  56.     }
  57. }
  58.  
  59. int main() {
  60.     citire();
  61.     bfs(7); // CHANGE ME!!
  62.     return 0;
  63. }
  64.  
  65.  
  66. /** DATE DE INTRARE!!! fis.in
  67. 10 15
  68. 1 2
  69. 1 3
  70. 1 4
  71. 2 4
  72. 1 10
  73. 10 9
  74. 5 10
  75. 8 10
  76. 3 6
  77. 3 7
  78. 6 2
  79. 7 4
  80. 2 5
  81. 4 8
  82. 6 7
  83. */
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×