Language: C++

#include <bits/stdc++.h>

using namespace std;

const int INF = 1 << 30;

struct Dinic
{
  const int INF = 1 << 30;

  struct edge
  {
    int to, cap, rev;
  };

  vector< vector< edge > > graph;
  vector< int > min_cost, iter;

  Dinic(int n)
  {
    graph.resize(n);
  }

  void add_edge(int from, int to, int cap)
  {
    graph[from].push_back((edge) {to, cap, (int) graph[to].size()});
    graph[to].push_back((edge) {from, 0, (int) graph[from].size() - 1});
  }

  bool bfs(int s, int t)
  {
    min_cost.assign(graph.size(), -1);
    queue< int > que;
    min_cost[s] = 0;
    que.push(s);
    while(!que.empty()) {
      int p = que.front();
      que.pop();
      for(int i = 0; i < graph[p].size(); i++) {
        const edge &e = graph[p][i];
        if(e.cap > 0 && min_cost[e.to] == -1) {
          min_cost[e.to] = min_cost[p] + 1;
          que.push(e.to);
        }
      }
    }
    return (min_cost[t] != -1);
  }

  int dfs(int idx, const int t, int flow)
  {
    if(idx == t) return (flow);
    for(int &i = iter[idx]; i < graph[idx].size(); i++) {
      edge &e = graph[idx][i];
      if(e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
        int d = dfs(e.to, t, min(flow, e.cap));
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return (d);
        }
      }
    }
    return (0);
  }

  int max_flow(int s, int t)
  {
    int flow = 0;
    while(bfs(s, t)) {
      iter.assign(graph.size(), 0);
      int f = 0;
      while((f = dfs(s, t, INF)) > 0) {
        flow += f;
      }
    }
    return (flow);
  }

  bool back_edge(int from, int to)
  {
    for(edge &e : graph[from]) {
      if(e.to == to && e.alive) {
        e.alive = false;
        if(e.cap == 0 && max_flow(from, to, 1) == 0) {
          max_flow(from, 0, 1);
          max_flow(graph.size() - 1, to, 1);
          return (1);
        } else {
          return (0);
        }
      }
    }
  }

};

int main()
{
  int N, E, Q;
  cin >> N >> E >> Q;
  Dinic graph(N);
  while(E--) {
    int F, T;
    cin >> F >> T;
    --F, --T;
    graph.add_edge(F, T, 1);
  }
  int flow = graph.max_flow(0, N - 1, INF);
  while(Q--) {
    int M, A, B;
    cin >> M >> A >> B;
    --A, --B;
    if(M == 1) {
      graph.add_edge(A, B, 1);
      flow += graph.max_flow(0, N - 1, 1);
    } else {
      flow -= graph.back_edge(A, B);
      flow -= graph.back_edge(B, A);
    }
    cout << flow << endl;
  }
}

Compiler output:
a.cc: In member function 'bool Dinic::back_edge(int, int)':
a.cc:83:26: error: 'struct Dinic::edge' has no member named 'alive'
   83 |       if(e.to == to && e.alive) {
      |                          ^~~~~
a.cc:84:11: error: 'struct Dinic::edge' has no member named 'alive'
   84 |         e.alive = false;
      |           ^~~~~
a.cc:85:34: error: no matching function for call to 'Dinic::max_flow(int&, int&, int)'
   85 |         if(e.cap == 0 && max_flow(from, to, 1) == 0) {
      |                          ~~~~~~~~^~~~~~~~~~~~~
a.cc:67:7: note: candidate: 'int Dinic::max_flow(int, int)'
   67 |   int max_flow(int s, int t)
      |       ^~~~~~~~
a.cc:67:7: note:   candidate expects 2 arguments, 3 provided
a.cc:86:19: error: no matching function for call to 'Dinic::max_flow(int&, int, int)'
   86 |           max_flow(from, 0, 1);
      |           ~~~~~~~~^~~~~~~~~~~~
a.cc:67:7: note: candidate: 'int Dinic::max_flow(int, int)'
   67 |   int max_flow(int s, int t)
      |       ^~~~~~~~
a.cc:67:7: note:   candidate expects 2 arguments, 3 provided
a.cc:87:19: error: no matching function for call to 'Dinic::max_flow(std::vector<std::vector<Dinic::edge> >::size_type, int&, int)'
   87 |           max_flow(graph.size() - 1, to, 1);
      |           ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:67:7: note: candidate: 'int Dinic::max_flow(int, int)'
   67 |   int max_flow(int s, int t)
      |       ^~~~~~~~
a.cc:67:7: note:   candidate expects 2 arguments, 3 provided
a.cc: In function 'int main()':
a.cc:109:28: error: no matching function for call to 'Dinic::max_flow(int, int, const int&)'
  109 |   int flow = graph.max_flow(0, N - 1, INF);
      |              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
a.cc:67:7: note: candidate: 'int Dinic::max_flow(int, int)'
   67 |   int max_flow(int s, int t)
      |       ^~~~~~~~
a.cc:67:7: note:   candidate expects 2 arguments, 3 provided
a.cc:116:29: error: no matching function for call to 'Dinic::max_flow(int, int, int)'
  116 |       flow += graph.max_flow(0, N - 1, 1);
      |               ~~~~~~~~~~~~~~^~~~~~~~~~~~~
a.cc:67:7: note: candidate: 'int Dinic::max_flow(int, int)'
   67 |   int max_flow(int s, int t)
      |       ^~~~~~~~
a.cc:67:7: note:   candidate expects 2 arguments, 3 provided
a.cc: In member function 'bool Dinic::back_edge(int, int)':
a.cc:94:3: warning: control reaches end of non-void function [-Wreturn-type]
   94 |   }
      |   ^