fork(1) download
  1. #include<iostream>
  2.  
  3. #include<queue>
  4.  
  5. #include<vector>
  6.  
  7.  
  8.  
  9. using namespace std;
  10.  
  11.  
  12.  
  13. int A[30][30];
  14.  
  15.  
  16.  
  17. void BFS(int N, int s) {
  18.  
  19. vector<bool> V(N, false);
  20.  
  21. queue<int> Q;
  22.  
  23. Q.push(s);
  24.  
  25. V[s] = true;
  26.  
  27. while(!Q.empty()) {
  28.  
  29. int u = Q.front();
  30.  
  31. cout << u << " ";
  32.  
  33. Q.pop();
  34.  
  35. for(int v = 1; v <= N; v++)v {
  36.  
  37. if(A[u][v]) {
  38.  
  39. if(V[v] == false) {
  40.  
  41. V[v] = true;
  42.  
  43. Q.push(v);
  44.  
  45. }
  46.  
  47. }
  48.  
  49. }
  50.  
  51. }
  52.  
  53. coput << endl;
  54.  
  55. }
  56.  
  57.  
  58.  
  59. int main() {
  60.  
  61. int N, M;
  62.  
  63. cin >> N >> M;
  64.  
  65. for(int i = 0; i < M; i++) {
  66.  
  67. int u, v;
  68.  
  69. cin >> u >> v;
  70.  
  71. A[u][v] = 1;
  72.  
  73. A[v][u] = 1;
  74.  
  75. }
  76.  
  77. BFS(N, 1);
  78.  
  79. return 0;
  80.  
  81. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
4 5
1 2
2 3
1 3
4 5
3 4
compilation info
prog.cpp: In function 'void BFS(int, int)':
prog.cpp:35:32: error: expected ';' before '{' token
   for(int v = 1; v <= N; v++)v {
                                ^
prog.cpp:81:1: error: expected '}' at end of input
 } 
 ^
prog.cpp:81:1: error: expected '}' at end of input
stdout
Standard output is empty