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