fork download
  1. #include<stdio.h>
  2. #include<iostream>
  3. #define WHITE 1
  4. #define GRAY 2
  5. #define BLACK 3
  6. using namespace std;
  7.  
  8. int adj[100][100];
  9. int color[100];
  10. int node,edge;
  11.  
  12. void dfsvisit(int x){
  13. color[x]=GRAY;
  14. for(int i=0;i<node;++i){
  15. if(adj[x][i]==1){
  16. if(adj[i]==WHITE){
  17. dfsvisit(i);
  18. }
  19. }
  20. }
  21. color[x]=BLACK;
  22. }
  23. void dfs(){
  24. for(int i=0;i<node;++i){
  25. colo[i]=WHITE;
  26. }
  27. for(int i=0;i<node;++i){
  28. if(color[i]==WHITE){
  29. dfsvisit(i);
  30. }
  31. }
  32. }
  33.  
  34. int main(){
  35. int n1,n2;
  36. scanf("%d%d",&node,&edge);
  37. for(int i=0;i<edge;++i){
  38. scanf("%d%d",&n1,&n2);
  39. adj[n1][n2]=1;
  40. adj[n2][n1]=1;
  41. }
  42. dfs();
  43. return 0;
  44. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void dfsvisit(int)’:
prog.cpp:16:16: warning: init-statement in selection statements only available with -std=c++17 or -std=gnu++17
             if(adj[i]==WHITE){
                ^~~
prog.cpp:3:15: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
 #define WHITE 1 ;
               ^
prog.cpp:16:24: note: in expansion of macro ‘WHITE’
             if(adj[i]==WHITE){
                        ^~~~~
prog.cpp:16:29: error: expected primary-expression before ‘)’ token
             if(adj[i]==WHITE){
                             ^
prog.cpp: In function ‘void dfs()’:
prog.cpp:25:9: error: ‘colo’ was not declared in this scope
         colo[i]=WHITE;
         ^~~~
prog.cpp:25:9: note: suggested alternative: ‘color’
         colo[i]=WHITE;
         ^~~~
         color
prog.cpp:28:12: warning: init-statement in selection statements only available with -std=c++17 or -std=gnu++17
         if(color[i]==WHITE){
            ^~~~~
prog.cpp:28:27: error: expected primary-expression before ‘)’ token
         if(color[i]==WHITE){
                           ^
prog.cpp: In function ‘int main()’:
prog.cpp:36:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&node,&edge);
     ~~~~~^~~~~~~~~~~~~~~~~~~~
prog.cpp:38:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&n1,&n2);
         ~~~~~^~~~~~~~~~~~~~~~
stdout
Standard output is empty