fork download
  1. define gc() (*_pinp?*_pinp++:(_inp[fread(_pinp=_inp, 1, 4096, stdin)]='\0', *_pinp++))
  2. char _inp[4097], *_pinp=_inp, _; bool _ssign;
  3. #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
  4. #include <cstdio>
  5. #include <vector>
  6. using namespace std;
  7. int N, M, p[150], r[150];
  8. int size[150];
  9. void MAKE_SET(int x) {
  10. p[x]=x;
  11. r[x]=0;
  12. size[x]=1;
  13. }
  14. int FIND_SET(int x) {
  15. if (p[x]!=x)
  16. p[x]=FIND_SET(p[x]);
  17. return p[x];
  18. }
  19. void UNION(int x, int y) {
  20. int xr=FIND_SET(x);
  21. int yr=FIND_SET(y);
  22. if (xr==yr) return;
  23. if (r[xr]<r[yr]) {
  24. p[xr]=yr;
  25. size[xr]+=size[yr];
  26. } else if (r[xr]>r[yr]) {
  27. p[yr]=xr;
  28. size[yr]+=size[xr];
  29. } else {
  30. p[yr]=xr;
  31. r[xr]++;
  32. size[yr]+=size[xr];
  33. }
  34. }
  35. vector<int> a;
  36. int main() {
  37. nextInt(N);
  38. nextInt(M);
  39. for (int i=0; i<N; i++)
  40. MAKE_SET(i);
  41. for (int i=0; i<M; i++) {
  42. int u, v;
  43. nextInt(u);
  44. nextInt(v);
  45. if (FIND_SET(u)!=FIND_SET(v)) {
  46. a.push_back(i+1);
  47. UNION(u, v);
  48. }
  49. }
  50. int p=FIND_SET(0);
  51. for (int i=0; i<N; i++) {
  52. if (p!=FIND_SET(i)) {printf("Disconnected Graph\n"); return 0;}
  53. }
  54. for (int i=0; i<a.size(); i++)
  55. printf("%i\n", a[i]);
  56. return 0;
  57. }
  58.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
100 10
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
2 35
3 26
compilation info
prog.cpp:1:1: error: ‘define’ does not name a type
 define gc() (*_pinp?*_pinp++:(_inp[fread(_pinp=_inp, 1, 4096, stdin)]='\0', *_pinp++))
 ^~~~~~
prog.cpp: In function ‘int main()’:
prog.cpp:3:35: error: ‘gc’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                   ^
prog.cpp:37:5: note: in expansion of macro ‘nextInt’
     nextInt(N);
     ^~~~~~~
prog.cpp:3:82: error: ‘gc’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                                                                  ^
prog.cpp:37:5: note: in expansion of macro ‘nextInt’
     nextInt(N);
     ^~~~~~~
prog.cpp:3:109: error: ‘_’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                                                                                             ^
prog.cpp:37:5: note: in expansion of macro ‘nextInt’
     nextInt(N);
     ^~~~~~~
prog.cpp:3:114: error: ‘gc’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                                                                                                  ^
prog.cpp:37:5: note: in expansion of macro ‘nextInt’
     nextInt(N);
     ^~~~~~~
prog.cpp:3:35: error: ‘gc’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                   ^
prog.cpp:38:5: note: in expansion of macro ‘nextInt’
     nextInt(M);
     ^~~~~~~
prog.cpp:3:82: error: ‘gc’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                                                                  ^
prog.cpp:38:5: note: in expansion of macro ‘nextInt’
     nextInt(M);
     ^~~~~~~
prog.cpp:3:109: error: ‘_’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                                                                                             ^
prog.cpp:38:5: note: in expansion of macro ‘nextInt’
     nextInt(M);
     ^~~~~~~
prog.cpp:3:114: error: ‘gc’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                                                                                                  ^
prog.cpp:38:5: note: in expansion of macro ‘nextInt’
     nextInt(M);
     ^~~~~~~
prog.cpp:3:35: error: ‘gc’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                   ^
prog.cpp:43:3: note: in expansion of macro ‘nextInt’
   nextInt(u);
   ^~~~~~~
prog.cpp:3:82: error: ‘gc’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                                                                  ^
prog.cpp:43:3: note: in expansion of macro ‘nextInt’
   nextInt(u);
   ^~~~~~~
prog.cpp:3:109: error: ‘_’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                                                                                             ^
prog.cpp:43:3: note: in expansion of macro ‘nextInt’
   nextInt(u);
   ^~~~~~~
prog.cpp:3:114: error: ‘gc’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                                                                                                  ^
prog.cpp:43:3: note: in expansion of macro ‘nextInt’
   nextInt(u);
   ^~~~~~~
prog.cpp:3:35: error: ‘gc’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                   ^
prog.cpp:44:3: note: in expansion of macro ‘nextInt’
   nextInt(v);
   ^~~~~~~
prog.cpp:3:82: error: ‘gc’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                                                                  ^
prog.cpp:44:3: note: in expansion of macro ‘nextInt’
   nextInt(v);
   ^~~~~~~
prog.cpp:3:109: error: ‘_’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                                                                                             ^
prog.cpp:44:3: note: in expansion of macro ‘nextInt’
   nextInt(v);
   ^~~~~~~
prog.cpp:3:114: error: ‘gc’ was not declared in this scope
 #define nextInt(x) do{while((x=gc())<'-'); _ssign=x=='-'; if(_ssign) while((x=gc())<'0'); for(x-='0'; '0'<=(_=gc()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
                                                                                                                  ^
prog.cpp:44:3: note: in expansion of macro ‘nextInt’
   nextInt(v);
   ^~~~~~~
stdout
Standard output is empty