Language: C++

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

bool hoge(int cur, vector< vector<int> >& g, vector<int>& color) {
    for (int i : g[cur]) {
        if (color[i] == color[cur]) return false;
        if (color[i] == -1) {
            color[i] = !color[cur];
            if (!hoge(i, g, color)) return false;
        }
    }
    return true;
}

bool link[705][705];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        link[a][b] = true;
        link[b][a] = true;
    }

    vector< vector<int> > g(n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (!link[i][j]) {
                g[i].push_back(j);
                g[j].push_back(i);
                add_edge(i, j);
            }
        }
    }

    vector<int> color(n, -1);
    vector<int> dp(n + 1, false);
    dp[0] = true;
    for (int i = 0; i < n; i++) {
        if (color[i] == -1) {
            color[i] = 0;
            if (!hoge(i, g, color)) {
                cout << -1 << endl;
                return 0;
            }

            vector<int> cnt(2, 0);
            for (int j = 0; j < n; j++) {
                if (color[j] <= -1) continue;
                cnt[color[j]]++;
                color[j] = -2;
            }

            for (int j = n; j >= 0; j--) {
                dp[j] |= (j - cnt[0] >= 0 && dp[j - cnt[0]]);
                dp[j] |= (j - cnt[1] >= 0 && dp[j - cnt[1]]);
            }
        }
    }

    int ans = m;
    for (int i = 1; i <= n; i++) {
        if (!dp[i]) continue;
        ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2 );
    }

    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc:18:19: error: 'bool link [705][705]' redeclared as different kind of entity
   18 | bool link[705][705];
      |                   ^
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/14/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:116,
                 from a.cc:1:
/usr/include/unistd.h:819:12: note: previous declaration 'int link(const char*, const char*)'
  819 | extern int link (const char *__from, const char *__to)
      |            ^~~~
a.cc: In function 'int main()':
a.cc:29:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   29 |         link[a][b] = true;
      |               ^
a.cc:29:18: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   29 |         link[a][b] = true;
      |                  ^
a.cc:29:20: error: assignment of read-only location '*(link + (((sizetype)a) + ((sizetype)b)))'
   29 |         link[a][b] = true;
      |         ~~~~~~~~~~~^~~~~~
a.cc:30:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   30 |         link[b][a] = true;
      |               ^
a.cc:30:18: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   30 |         link[b][a] = true;
      |                  ^
a.cc:30:20: error: assignment of read-only location '*(link + (((sizetype)b) + ((sizetype)a)))'
   30 |         link[b][a] = true;
      |         ~~~~~~~~~~~^~~~~~
a.cc:36:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   36 |             if (!link[i][j]) {
      |                        ^
a.cc:36:27: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   36 |             if (!link[i][j]) {
      |                           ^
a.cc:39:17: error: 'add_edge' was not declared in this scope
   39 |                 add_edge(i, j);
      |                 ^~~~~~~~