fork(1) download
  1. const int MAXN = ...; // число вершин
  2. const int INF = 1000000000; // константа-бесконечность
  3.  
  4. struct edge {
  5. int a, b, cap, flow;
  6. };
  7.  
  8. int n, s, t, d[MAXN], ptr[MAXN], q[MAXN];
  9. vector<edge> e;
  10. vector<int> g[MAXN];
  11.  
  12. void add_edge (int a, int b, int cap) {
  13. edge e1 = { a, b, cap, 0 };
  14. edge e2 = { b, a, 0, 0 };
  15. g[a].push_back ((int) e.size());
  16. e.push_back (e1);
  17. g[b].push_back ((int) e.size());
  18. e.push_back (e2);
  19. }
  20.  
  21. bool bfs() {
  22. int qh=0, qt=0;
  23. q[qt++] = s;
  24. memset (d, -1, n * sizeof d[0]);
  25. d[s] = 0;
  26. while (qh < qt && d[t] == -1) {
  27. int v = q[qh++];
  28. for (size_t i=0; i<g[v].size(); ++i) {
  29. int id = g[v][i],
  30. to = e[id].b;
  31. if (d[to] == -1 && e[id].flow < e[id].cap) {
  32. q[qt++] = to;
  33. d[to] = d[v] + 1;
  34. }
  35. }
  36. }
  37. return d[t] != -1;
  38. }
  39.  
  40. int dfs (int v, int flow) {
  41. if (!flow) return 0;
  42. if (v == t) return flow;
  43. for (; ptr[v]<(int)g[v].size(); ++ptr[v]) {
  44. int id = g[v][ptr[v]],
  45. to = e[id].b;
  46. if (d[to] != d[v] + 1) continue;
  47. int pushed = dfs (to, min (flow, e[id].cap - e[id].flow));
  48. if (pushed) {
  49. e[id].flow += pushed;
  50. e[id^1].flow -= pushed;
  51. return pushed;
  52. }
  53. }
  54. return 0;
  55. }
  56.  
  57. int dinic() {
  58. int flow = 0;
  59. for (;;) {
  60. if (!bfs()) break;
  61. memset (ptr, 0, n * sizeof ptr[0]);
  62. while (int pushed = dfs (s, INF))
  63. flow += pushed;
  64. }
  65. return flow;
  66. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:18: error: expected primary-expression before ‘...’ token
 const int MAXN = ...; // число вершин
                  ^~~
prog.cpp:8:20: error: size of array ‘d’ is not an integral constant-expression
 int n, s, t, d[MAXN], ptr[MAXN], q[MAXN];
                    ^
prog.cpp:8:31: error: size of array ‘ptr’ is not an integral constant-expression
 int n, s, t, d[MAXN], ptr[MAXN], q[MAXN];
                               ^
prog.cpp:8:40: error: size of array ‘q’ is not an integral constant-expression
 int n, s, t, d[MAXN], ptr[MAXN], q[MAXN];
                                        ^
prog.cpp:9:1: error: ‘vector’ does not name a type
 vector<edge> e;
 ^~~~~~
prog.cpp:10:1: error: ‘vector’ does not name a type
 vector<int> g[MAXN];
 ^~~~~~
prog.cpp: In function ‘void add_edge(int, int, int)’:
prog.cpp:15:2: error: ‘g’ was not declared in this scope
  g[a].push_back ((int) e.size());
  ^
prog.cpp:15:24: error: ‘e’ was not declared in this scope
  g[a].push_back ((int) e.size());
                        ^
prog.cpp: In function ‘bool bfs()’:
prog.cpp:24:32: error: ‘memset’ was not declared in this scope
  memset (d, -1, n * sizeof d[0]);
                                ^
prog.cpp:28:8: error: ‘size_t’ was not declared in this scope
   for (size_t i=0; i<g[v].size(); ++i) {
        ^~~~~~
prog.cpp:28:20: error: ‘i’ was not declared in this scope
   for (size_t i=0; i<g[v].size(); ++i) {
                    ^
prog.cpp:28:22: error: ‘g’ was not declared in this scope
   for (size_t i=0; i<g[v].size(); ++i) {
                      ^
prog.cpp:31:10: error: ‘to’ was not declared in this scope
    if (d[to] == -1 && e[id].flow < e[id].cap) {
          ^~
prog.cpp:31:23: error: ‘e’ was not declared in this scope
    if (d[to] == -1 && e[id].flow < e[id].cap) {
                       ^
prog.cpp: In function ‘int dfs(int, int)’:
prog.cpp:43:21: error: ‘g’ was not declared in this scope
  for (; ptr[v]<(int)g[v].size(); ++ptr[v]) {
                     ^
prog.cpp:46:9: error: ‘to’ was not declared in this scope
   if (d[to] != d[v] + 1)  continue;
         ^~
prog.cpp:47:21: error: ‘to’ was not declared in this scope
   int pushed = dfs (to, min (flow, e[id].cap - e[id].flow));
                     ^~
prog.cpp:47:36: error: ‘e’ was not declared in this scope
   int pushed = dfs (to, min (flow, e[id].cap - e[id].flow));
                                    ^
prog.cpp:47:58: error: ‘min’ was not declared in this scope
   int pushed = dfs (to, min (flow, e[id].cap - e[id].flow));
                                                          ^
prog.cpp: In function ‘int dinic()’:
prog.cpp:61:36: error: ‘memset’ was not declared in this scope
   memset (ptr, 0, n * sizeof ptr[0]);
                                    ^
stdout
Standard output is empty