fork download
  1. #include <iostream>
  2. #include <queue>
  3. #define MAX 100000
  4. using namespace std;
  5.  
  6.  
  7. int check[MAX+1];
  8. int mat[MAX+1][MAX+1];
  9. int n,m,v;
  10.  
  11. void bfs(int v){
  12. queue<int> q;
  13. q.push(v);
  14. check[v] = 0;
  15. while(!q.empty()){
  16. cout << v << ' ';
  17. q.pop();
  18. for(int i=1;i<=n;i++){
  19. if(check[v] == 0 && mat[v][i] == 0){
  20. continue;
  21. }
  22. q.push(i);
  23. check[i] == 0;
  24. }
  25. }
  26. }
  27. void dfs(int v){
  28. cout << v << ' ';
  29. check[v] = 1;
  30. for(int i=1;i<=n;i++){
  31. if(check[v] == 1 && mat[v][i] == 0){
  32. continue;
  33. }
  34. dfs(i);
  35. }
  36. }
  37.  
  38. int main(void){
  39. cin >> n >> m >> v;
  40. for(int i=0;i<m;i++){
  41. int x,y;
  42. cin >> x >> y;
  43. mat[x][y] = 1;
  44. mat[y][x] = 1;
  45. }
  46. bfs(v);
  47. cout << '\n';
  48. dfs(v);
  49. return 0;
  50. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
4 5 1
1 2
1 3
1 4
2 4
3 4
compilation info
/home/hBMSPq/cccb1Esa.o: In function `dfs(int)':
prog.cpp:(.text+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `check' defined in .bss section in /home/hBMSPq/cccb1Esa.o
/home/hBMSPq/cccb1Esa.o: In function `bfs(int)':
prog.cpp:(.text+0x2ef): relocation truncated to fit: R_X86_64_PC32 against symbol `check' defined in .bss section in /home/hBMSPq/cccb1Esa.o
/home/hBMSPq/cccb1Esa.o: In function `_GLOBAL__sub_I_check':
prog.cpp:(.text.startup+0x103): relocation truncated to fit: R_X86_64_PC32 against `.bss'
prog.cpp:(.text.startup+0x121): relocation truncated to fit: R_X86_64_PC32 against `.bss'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty