Language: C++

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

struct Edge {
  int from, to;
  int id;
  int reverse_id;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;

  vector<vector<Edge>> graph(n);
  vector<Edge> edges;
  vector<int> is_actives(2 * m);
  vector<int> out_degrees(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    v1--; v2--;
    Edge e1({v1, v2, 2 * i, 2 * i + 1});
    Edge e2({v2, v1, 2 * i + 1, 2 * i});
    graph[v1].push_back(e1);
    graph[v2].push_back(e2);
    edges.push_back(e1);
    edges.push_back(e2);
    is_actives[2 * i] = true;
    out_degrees[v1]++;
  }

  if (m % 2 == 1) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> visited(n, 0);
  vector<int> used_edges(n, -1);
  function<void(int, int)> dfs =
      function<void(int, int)>([&] (int v, int parent) {
        visited[v] = 1;
        for (const auto& edge : graph[v]) {
          if (edge.to == parent) continue;
          if (visited[edge.to]) continue;
          used_edges[edge.to] = edge.id;
          dfs(edge.to, v);
        }
        if (out_degrees[v] % 2 == 1) {
          int edge_id = used_edges[v];
          int reverse_edge_id = edges[edge_id].reverse_id;
          if (is_actives[edge_id]) {
            out_degrees[edges[edge_id].from]--;
            out_degrees[edges[edge_id].to]++;
            is_actives[edge_id] = false;
            is_actives[edges[used_edges[v]].reverse_id] = true;
          } else {
            out_degrees[edges[edge_id].to]++;
            out_degrees[edges[edge_id].from]--;
            is_actives[edge_id] = true;
            is_actives[edges[used_edges[v]].reverse_id] = false;
          }
        }
      });
  

  while (true) {
    bool is_finished = true;
    for (int i = 0; i < n; i++) {
      if (out_degrees[i] % 2 == 1) is_finished = false;
    }
    if (is_finished) break;

    for (int s = 0; s < n; s++) {
      if (out_degrees[s] % 2 == 1) {
        int t = dfs(s, s, -1);
        if (t < 0) continue;
        int cur = t;
        while (cur != s) {
          Edge used_edge = edges[used_edges[cur]];
          if (is_actives[used_edge.id]) {
            out_degrees[used_edge.from]--;
            out_degrees[used_edge.to]++;
          } else {
            out_degrees[used_edge.from]++;
            out_degrees[used_edge.to]--;
          }
          is_actives[used_edge.id] = !is_actives[used_edge.id];
          is_actives[used_edge.reverse_id] = !is_actives[used_edge.reverse_id];

          cur = used_edge.from;
        }
      }
    }

    for (int i = 0; i < n; i++) visited[i] = 0;
    for (int i = 0; i < n; i++) used_edges[i] = -1;
  }

  for (int i = 0; i < 2 * m; i++) {
    if (is_actives[i]) {
      cout << edges[i].from + 1 << " " << edges[i].to + 1 << endl;
    }
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:81:20: error: no match for call to '(std::function<void(int, int)>) (int&, int&, int)'
   81 |         int t = dfs(s, s, -1);
      |                 ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/functional:59,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/std_function.h:587:7: note: candidate: '_Res std::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const [with _Res = void; _ArgTypes = {int, int}]'
  587 |       operator()(_ArgTypes... __args) const
      |       ^~~~~~~~
/usr/include/c++/14/bits/std_function.h:587:7: note:   candidate expects 2 arguments, 3 provided