Language: C++

#include<bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(a) "(" << #a << ": " << (a) << ")"

template<typename T>
void chmin(T &x, T y) { x = min(x, y); }

template<typename T>
void chmax(T &x, T y) { x = max(x, y); }

typedef long long int lli;
typedef long double ld;
typedef tuple<int,int> P;

const int INF = INT_MAX/2 - 1;
const double EPS = 1e-14;
const int dx[4] = {0, 1, 0, -1}; // {-1,  0,  1, -1, 1, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0}; // {-1, -1, -1,  0, 0,  1, 1, 1};

typedef int Weight;
typedef int Flow;

struct Edge {
  int src, dest, rev;
  Flow cap;
  Weight cost;
  bool operator < (const Edge &rhs) const {
    return cost > rhs.cost;
  }
  Edge(int s, int d) : src(s), dest(d) { ; }
  Edge(int s, int d, int c) : src(s), dest(d), cost(c) { ; }
  Edge(int s, int d, int r, Flow cp, Weight cst) : src(s), dest(d), rev(r), cap(cp), cost(cst) { ; }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int src, int dest, Flow cap){
  g[src].push_back((Edge){src, dest, (int)g[dest].size(), cap, 0});
  g[dest].push_back((Edge){dest, src, (int)g[src].size()-1, 0, 0});
}

Flow dfs(Graph &g, vector<bool> &used, int v, int t, Flow f){
  if(v == t) return f;
  used[v] = true;
  for(Edge& e: g[v]){
    if(!used[e.dest] && e.cap > 0){
      Flow d = dfs(g, used, e.dest, t, min(f,e.cap));
      if(d > 0){
        e.cap -= d;
        g[e.dest][e.rev].cap += d;
      return d;
      }
    }
  }
  return 0;
}

Flow ford_fulkerson(Graph &g, int s, int t){
  Flow flow = 0;
  for(;;){
    vector<bool> used(g.size(),false);
    Flow f = dfs(g,used,s,t,INF);
    if(f == 0) return flow;
    flow += f;
  }
}

void addEdge(Graph &g, int from, int to, Flow cap, Weight cost) {
  g[from].push_back(Edge(from, to, (int)g[to].size(), cap, cost));
  g[to].push_back(Edge(to, from, (int)g[from].size() - 1, 0, -cost));
}

Weight minCostFlow(Graph &g, int s, int t, Flow f) {
  int V = g.size();
  Weight res = 0;
  vector<Weight> dist(V);
  vector<int> prevv(V), preve(V);
  while (f > 0) {
    REP(i, V) dist[i] = (i == s) ? 0 : INF;
    bool update = true;
    while (update) {
      update = false;
      for (int v = 0; v < V; v++) {
        if (dist[v] == INF) continue;
        REP(i, g[v].size()) {
          Edge e = g[v][i];
          if (e.cap > 0 && dist[e.dest] > dist[v] + e.cost) {
            dist[e.dest] = dist[v] + e.cost;
            prevv[e.dest] = v;
            preve[e.dest] = i;
            update = true;
          }
        }
      }
    }
    if (dist[t] == INF) return -1; // cannot flow

    Flow d = f;
    for (int v = t; v != s; v = prevv[v]) {
      d = min(d, g[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * dist[t];
    for (int v = t; v != s; v = prevv[v]) {
      Edge &e = g[prevv[v]][preve[v]];
      e.cap -= d;
      g[v][e.rev].cap += d;
    }
  }
  return res;
}


int main() {
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<P> edges(N);
  set<int> lengs;
  REP(i, N) {
    int a, b;
    cin >> a >> b;
    get<0>(edges[i]) = a, get<1>(edges[i]) = b;
    lengs.insert(a); lengs.insert(b);
  }
  map<int,int> len, rlen;
  {
    int i = N;
    for (int l : lengs) {
      len[l] = i;
      rlen[i] = l;
      i++;
    }
  }
  const int l = lengs.size(), SOURCE = N + l, SINK = N + l + 1;
  Graph G(N + l + 2);
  REP(i, N) {
    int height = get<0>(edges[i]), width = get<1>(edges[i]);
    addEdge(G, SOURCE, i, 1, 0);
    addEdge(G, i, len[height], 1, -width);
    addEdge(G, i, len[width], 1, -height);
  }
  for (int l : lengs) {
    addEdge(G, len[l], SINK, 1, 0);
  }
  int ans = 0;
  /*REP(i, N + 1) {
    Graph F(G);
    int flow = -minCostFlow(F, SOURCE, SINK, i);
    chmax(ans, flow);
  }*/
  ans = -minCostFlow(F, SOURCE, SINK, 1) ;
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:161:22: error: 'F' was not declared in this scope
  161 |   ans = -minCostFlow(F, SOURCE, SINK, 1) ;
      |                      ^