Language: C++

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const int maxn = 703;

int n, m;
int vs[maxn], col[maxn];
vector<pair<int, int> > has;
vector<int> adj[maxn];
int D[maxn][maxn];
int cnt[2];
int G;

int cmp(pair<int, int> a, pair<int, int> b) {
  if (a.fi > a.se) swap(a.fi, a.se);
  if (b.fi > b.se) swap(b.fi, b.se);
  return a.se - a.fi > b.se - b.fi;
}

void dfs(int u, int co) {
  if (vs[u]) {
    if (col[u] != co) {
      cout << -1;
      exit(0);
    }
    return;
  }
  vs[u] = 1;
  cnt[co]++;
  col[u] = co;
  for (auto v : adj[u]) {
    dfs(v, co ^ 1);
  }
}

int main() {
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    D[x][y] = 1;
    D[y][x] = 1;
  }

  rep(i, 0, n) {
    rep(j, 0, n) {
      if (i == j) continue;
      if (D[i][j] == 0) adj[i].pb(j);
    }
  }

  rep(i, 0, n) {
    if (!vs[i]) {
      G++;
      cnt[0] = cnt[1] = 0;
      dfs(i, 0);
      has.pb(mp(cnt[0], cnt[1]));
    }
  }

  int cur1 = 0, cur2 = 0;

  sort(has.begin(), has.end, cmp);

  rep(i, 0, G) {
    if (cur1 > cur2) swap(cur1, cur2);
    cur1 += max(has[i].fi, has[i].se);
    cur2 += min(has[i].fi, has[i].se);
  }

  cout << ans;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:72:7: error: no matching function for call to 'sort(std::vector<std::pair<int, int> >::iterator, <unresolved overloaded function type>, int (&)(std::pair<int, int>, std::pair<int, int>))'
   72 |   sort(has.begin(), has.end, cmp);
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:4762:5: note: candidate: 'template<class _RAIter> void std::sort(_RAIter, _RAIter)'
 4762 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4762:5: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/14/bits/stl_algo.h:4793:5: note: candidate: 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pair<int, int>*, vector<pair<int, int> > >; _Compare = int (*)(pair<int, int>, pair<int, int>)]'
 4793 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4793:63: note:   no known conversion for argument 2 from '<unresolved overloaded function type>' to '__gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >'
 4793 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |                                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note:   candidate expects 4 arguments, 3 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/pstl/glue_algorithm_defs.h:15:
/usr/include/c++/14/pstl/execution_defs.h: In substitution of 'template<class _ExecPolicy, class _Tp> using __pstl::__internal::__enable_if_execution_policy = typename std::enable_if<__pstl::execution::v1::is_execution_policy<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value, _Tp>::type [with _ExecPolicy = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Tp = void]':
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1:   required by substitution of 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator) [with _ExecutionPolicy = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _RandomAccessIterator = int (*)(std::pair<int, int>, std::pair<int, int>)]'
a.cc:72:7:   required from here
   72 |   sort(has.begin(), has.end, cmp);
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/pstl/execution_defs.h:82:7: error: no type named 'type' in 'struct std::enable_if<false, void>'
   82 | using __enable_if_execution_policy =
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:80:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   80 |   cout << ans;
      |           ^~~
      |           abs