Language: C++

#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <queue>

template <class T>
constexpr T inf=(T(1)<<(8*sizeof(T)-3));

template <class Weight>
struct Edge {
  size_t src, dst;
  Weight cost;

  Edge(size_t src, size_t dst, Weight cost=1):
    src(src), dst(dst), cost(cost)
  {}

  bool operator <(const Edge<Weight> &rhs) const {
    if (cost != rhs.cost) return cost < rhs.cost;
    if (src != rhs.src) return src < rhs.src;
    return dst < rhs.dst;
  }
};

template <class Weight>
using Graph=std::vector<std::vector<Edge<Weight>>>;

template <class Weight>
bool is_bipartite_component(
    const Graph<Weight> &g, size_t node, std::vector<int> &colors, 
    int color=1) {

  colors[node] = color;
  std::queue<size_t> q;
  q.emplace(node);
  while (!q.empty()) {
    size_t v=q.front();
    q.pop();
    for (const auto &e: g[v]) {
      if (color[v] == color[e.dst]) return false;
      if (color[e.dst]) continue;
      color[e.dst] = -color[v];
      q.emplace(e.dst);
    }
  }
  return true;
};

template <class Weight>
bool is_bipartite(const Graph<Weight> &g, std::vector<int> &colors) {
  int color=0;
  for (size_t i=0; i<g.size(); ++i) {
    if (!color[i] && !is_bipartite_component(g, i, colors, ++color))
      return false;

  return true;
}

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  Graph<int> g(N);
  for (size_t i=0; i<N; ++i) {
    size_t A, B;
    scanf("%zu %zu", &A, &B);
    --A;
    --B;

    g[A].emplace_back(A, B);
    g[B].emplace_back(B, A);
  }

  std::vector<int> color(N);
  if (is_bipartite(g, color)) {
    size_t B=std::count(color.begin(), color.end(), 1);
    printf("%zu\n", B*(N-B)-M);
  } else {
    printf("%zu\n", N*(N-1)/2-M);
  }
}



Compiler output:
a.cc: In function 'bool is_bipartite_component(Graph<Weight>&, size_t, std::vector<int>&, int)':
a.cc:41:16: error: invalid types 'int[size_t {aka long unsigned int}]' for array subscript
   41 |       if (color[v] == color[e.dst]) return false;
      |                ^
a.cc:43:28: error: invalid types 'int[size_t {aka long unsigned int}]' for array subscript
   43 |       color[e.dst] = -color[v];
      |                            ^
a.cc: In function 'bool is_bipartite(Graph<Weight>&, std::vector<int>&)':
a.cc:54:15: error: invalid types 'int[size_t {aka long unsigned int}]' for array subscript
   54 |     if (!color[i] && !is_bipartite_component(g, i, colors, ++color))
      |               ^
a.cc:60:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   60 | int main() {
      |         ^~
a.cc:60:9: note: remove parentheses to default-initialize a variable
   60 | int main() {
      |         ^~
      |         --
a.cc:60:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:60:12: error: a function-definition is not allowed here before '{' token
   60 | int main() {
      |            ^
a.cc:82:2: error: expected '}' at end of input
   82 | }
      |  ^
a.cc:51:69: note: to match this '{'
   51 | bool is_bipartite(const Graph<Weight> &g, std::vector<int> &colors) {
      |                                                                     ^