fork download
  1. template <unsigned int MAXN>
  2. struct GeneralMatching {
  3. array<int, MAXN + 1> visited, parent, origin, match, aux;
  4. int N;
  5.  
  6. array<vector<int>, MAXN + 1> graph;
  7. queue<int> que;
  8.  
  9. void add_edge(int u, int v) {
  10. graph[v].push_back(u);
  11. graph[u].push_back(v);
  12. }
  13.  
  14. void init(int n) {
  15. N = n;
  16. for (int i = 0; i <= n; ++i) {
  17. graph[i].clear();
  18. match[i] = aux[i] = parent[i] = 0;
  19. }
  20. }
  21.  
  22. void augment(int u, int v) {
  23. int parent_v = v, next_v;
  24. do {
  25. parent_v = parent[v];
  26. next_v = match[parent_v];
  27. match[v] = parent_v;
  28. match[parent_v] = v;
  29. v = next_v;
  30. } while (u != parent_v);
  31. }
  32.  
  33. int lca(int u, int v) {
  34. static int label = 0;
  35. ++label;
  36. while (!v || aux[v] != label) {
  37. if (v) {
  38. aux[v] = label;
  39. v = origin[parent[match[v]]];
  40. }
  41. swap<int>(u, v);
  42. }
  43. return v;
  44. }
  45.  
  46. void blossom(int v, int w, int a) {
  47. while (origin[v] != a) {
  48. parent[v] = w;
  49. w = match[v];
  50. if (visited[w] == 1) {
  51. que.push(w);
  52. visited[w] = 0;
  53. }
  54. origin[v] = origin[w] = a;
  55. v = parent[w];
  56. }
  57. }
  58.  
  59. bool bfs(int u) {
  60. fill(visited.begin() + 1, visited.begin() + 1 + N, -1);
  61. iota(origin.begin() + 1, origin.begin() + 1 + N, 1);
  62. que = queue<int>();
  63. que.push(u);
  64. visited[u] = 0;
  65. while (!que.empty()) {
  66. int v = que.front();
  67. que.pop();
  68. for (int x : graph[v]) {
  69. if (visited[x] == -1) {
  70. parent[x] = v;
  71. visited[x] = 1;
  72. if (!match[x]) {
  73. augment(u, x);
  74. return true;
  75. }
  76. que.push(match[x]);
  77. visited[match[x]] = 0;
  78. } else if (visited[x] == 0 && origin[v] != origin[x]) {
  79. int a = lca(origin[v], origin[x]);
  80. blossom(x, v, a);
  81. blossom(v, x, a);
  82. }
  83. }
  84. }
  85. return false;
  86. }
  87.  
  88. int Match() {
  89. int ans = 0;
  90. // find random matching (not necessary, constant improvement)
  91. vector<int> V(N - 1);
  92. iota(V.begin(), V.end(), 1);
  93. shuffle(V.begin(), V.end(), mt19937(0x94949));
  94. for (auto x : V)
  95. if (!match[x]) {
  96. for (auto y : graph[x]) {
  97. if (!match[y]) {
  98. match[x] = y;
  99. match[y] = x;
  100. ++ans;
  101. break;
  102. }
  103. }
  104. }
  105. for (int i = 1; i <= N; ++i) {
  106. if (!match[i] && bfs(i)) ++ans;
  107. }
  108. return ans;
  109. }
  110. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:3: error: ‘array’ does not name a type
   array<int, MAXN + 1> visited, parent, origin, match, aux;
   ^~~~~
prog.cpp:6:3: error: ‘array’ does not name a type
   array<vector<int>, MAXN + 1> graph;
   ^~~~~
prog.cpp:7:3: error: ‘queue’ does not name a type
   queue<int> que;
   ^~~~~
prog.cpp: In member function ‘void GeneralMatching<MAXN>::add_edge(int, int)’:
prog.cpp:10:5: error: ‘graph’ was not declared in this scope
     graph[v].push_back(u);
     ^~~~~
prog.cpp: In member function ‘void GeneralMatching<MAXN>::init(int)’:
prog.cpp:17:7: error: ‘graph’ was not declared in this scope
       graph[i].clear();
       ^~~~~
prog.cpp:18:7: error: ‘match’ was not declared in this scope
       match[i] = aux[i] = parent[i] = 0;
       ^~~~~
prog.cpp:18:18: error: ‘aux’ was not declared in this scope
       match[i] = aux[i] = parent[i] = 0;
                  ^~~
prog.cpp:18:27: error: ‘parent’ was not declared in this scope
       match[i] = aux[i] = parent[i] = 0;
                           ^~~~~~
prog.cpp: In member function ‘void GeneralMatching<MAXN>::augment(int, int)’:
prog.cpp:25:18: error: ‘parent’ was not declared in this scope
       parent_v = parent[v];
                  ^~~~~~
prog.cpp:26:16: error: ‘match’ was not declared in this scope
       next_v = match[parent_v];
                ^~~~~
prog.cpp: In member function ‘int GeneralMatching<MAXN>::lca(int, int)’:
prog.cpp:36:18: error: ‘aux’ was not declared in this scope
     while (!v || aux[v] != label) {
                  ^~~
prog.cpp:39:13: error: ‘origin’ was not declared in this scope
         v = origin[parent[match[v]]];
             ^~~~~~
prog.cpp:39:20: error: ‘parent’ was not declared in this scope
         v = origin[parent[match[v]]];
                    ^~~~~~
prog.cpp:39:27: error: ‘match’ was not declared in this scope
         v = origin[parent[match[v]]];
                           ^~~~~
prog.cpp:41:7: error: ‘swap’ was not declared in this scope
       swap<int>(u, v);
       ^~~~
prog.cpp:41:12: error: expected primary-expression before ‘int’
       swap<int>(u, v);
            ^~~
prog.cpp: In member function ‘void GeneralMatching<MAXN>::blossom(int, int, int)’:
prog.cpp:47:12: error: ‘origin’ was not declared in this scope
     while (origin[v] != a) {
            ^~~~~~
prog.cpp:48:7: error: ‘parent’ was not declared in this scope
       parent[v] = w;
       ^~~~~~
prog.cpp:49:11: error: ‘match’ was not declared in this scope
       w = match[v];
           ^~~~~
prog.cpp:50:11: error: ‘visited’ was not declared in this scope
       if (visited[w] == 1) {
           ^~~~~~~
prog.cpp:51:9: error: ‘que’ was not declared in this scope
         que.push(w);
         ^~~
prog.cpp: In member function ‘bool GeneralMatching<MAXN>::bfs(int)’:
prog.cpp:60:10: error: ‘visited’ was not declared in this scope
     fill(visited.begin() + 1, visited.begin() + 1 + N, -1);
          ^~~~~~~
prog.cpp:60:58: error: there are no arguments to ‘fill’ that depend on a template parameter, so a declaration of ‘fill’ must be available [-fpermissive]
     fill(visited.begin() + 1, visited.begin() + 1 + N, -1);
                                                          ^
prog.cpp:60:58: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
prog.cpp:61:10: error: ‘origin’ was not declared in this scope
     iota(origin.begin() + 1, origin.begin() + 1 + N, 1);
          ^~~~~~
prog.cpp:61:55: error: there are no arguments to ‘iota’ that depend on a template parameter, so a declaration of ‘iota’ must be available [-fpermissive]
     iota(origin.begin() + 1, origin.begin() + 1 + N, 1);
                                                       ^
prog.cpp:62:5: error: ‘que’ was not declared in this scope
     que = queue<int>();
     ^~~
prog.cpp:62:11: error: ‘queue’ was not declared in this scope
     que = queue<int>();
           ^~~~~
prog.cpp:62:17: error: expected primary-expression before ‘int’
     que = queue<int>();
                 ^~~
prog.cpp:62:17: error: expected ‘;’ before ‘int’
prog.cpp:68:20: error: ‘graph’ was not declared in this scope
       for (int x : graph[v]) {
                    ^~~~~
prog.cpp:70:11: error: ‘parent’ was not declared in this scope
           parent[x] = v;
           ^~~~~~
prog.cpp:72:16: error: ‘match’ was not declared in this scope
           if (!match[x]) {
                ^~~~~
prog.cpp:76:20: error: ‘match’ was not declared in this scope
           que.push(match[x]);
                    ^~~~~
prog.cpp: In member function ‘int GeneralMatching<MAXN>::Match()’:
prog.cpp:91:5: error: ‘vector’ was not declared in this scope
     vector<int> V(N - 1);
     ^~~~~~
prog.cpp:91:12: error: expected primary-expression before ‘int’
     vector<int> V(N - 1);
            ^~~
prog.cpp:92:10: error: ‘V’ was not declared in this scope
     iota(V.begin(), V.end(), 1);
          ^
prog.cpp:92:31: error: there are no arguments to ‘iota’ that depend on a template parameter, so a declaration of ‘iota’ must be available [-fpermissive]
     iota(V.begin(), V.end(), 1);
                               ^
prog.cpp:93:48: error: there are no arguments to ‘mt19937’ that depend on a template parameter, so a declaration of ‘mt19937’ must be available [-fpermissive]
     shuffle(V.begin(), V.end(), mt19937(0x94949));
                                                ^
prog.cpp:94:19: error: range-based ‘for’ expression of type ‘auto’ has incomplete type
     for (auto x : V)
                   ^
prog.cpp:95:12: error: ‘match’ was not declared in this scope
       if (!match[x]) {
            ^~~~~
prog.cpp:96:23: error: ‘graph’ was not declared in this scope
         for (auto y : graph[x]) {
                       ^~~~~
prog.cpp:106:12: error: ‘match’ was not declared in this scope
       if (!match[i] && bfs(i)) ++ans;
            ^~~~~
stdout
Standard output is empty