Language: C++

#include <iostream>
#include <stack>
#include <algorithm>
#include <string>
using namespace std;

bool is_bi_graph(int N, vector<vector<int>> all_es) {
    vector<int> colors(N, -1);
    stack<int> nodes;
    colors[0] = 0;
    nodes.push(0);
    while (!nodes.empty()) {
        int n = nodes.top();
        nodes.pop();
        int c = colors[n];
        int diff_c = c == 0 ? 1 : 0;
        for (int i = 0; i < N; ++i) {
            int cn = all_es[n][i];
            if (cn == 0) continue;
            int other_c = colors[i];
            if (other_c == c) return false;
            if (other_c == -1) {
                colors[i] = diff_c;
                nodes.push(i);
            }
        }
    }
    return true;
}

const int INF = 100000;
int calc_max_d(int N, vector<vector<int>> all_es) {
    vector<vector<int>> ds(N, vector<int>(N, 0));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            if (i == j) {
                ds[i][j] = 0;
            } else {
                int c = all_es[i][j];
                ds[i][j] = c == 0 ? INF : 1;
            }
        }
    }
    int max_d = 0;
    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                int d1 = ds[i][j];
                int d2 = ds[i][k];
                int d3 = ds[k][j];
                int d = min(d1, d2 + d3);
                ds[i][j] = d;
                if (d < INF && d > max_d && i != j) {
                    max_d = d;
                }
            }
        }
    }
    return max_d;
}

int main() {
    int N;
    cin >> N;
    vector<vector<int>> all_es(N, vector<int>(N, 0));
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < N; ++j) {
            char c = s[j];
            all_es[i][j] = c - '0';
        }
    }
    if (!is_bi_graph(N, all_es)) {
        cout << "-1\n";
        return 0;
    }
    int d = calc_max_d(N, all_es);
    cout << (d + 1) << "\n";
    return 0;
}

Compiler output:
a.cc:7:25: error: 'vector' has not been declared
    7 | bool is_bi_graph(int N, vector<vector<int>> all_es) {
      |                         ^~~~~~
a.cc:7:31: error: expected ',' or '...' before '<' token
    7 | bool is_bi_graph(int N, vector<vector<int>> all_es) {
      |                               ^
a.cc: In function 'bool is_bi_graph(int, int)':
a.cc:8:5: error: 'vector' was not declared in this scope
    8 |     vector<int> colors(N, -1);
      |     ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <algorithm>
  +++ |+#include <vector>
    4 | #include <string>
a.cc:8:12: error: expected primary-expression before 'int'
    8 |     vector<int> colors(N, -1);
      |            ^~~
a.cc:10:5: error: 'colors' was not declared in this scope
   10 |     colors[0] = 0;
      |     ^~~~~~
a.cc:18:22: error: 'all_es' was not declared in this scope
   18 |             int cn = all_es[n][i];
      |                      ^~~~~~
a.cc: At global scope:
a.cc:32:23: error: 'vector' has not been declared
   32 | int calc_max_d(int N, vector<vector<int>> all_es) {
      |                       ^~~~~~
a.cc:32:29: error: expected ',' or '...' before '<' token
   32 | int calc_max_d(int N, vector<vector<int>> all_es) {
      |                             ^
a.cc: In function 'int calc_max_d(int, int)':
a.cc:33:5: error: 'vector' was not declared in this scope
   33 |     vector<vector<int>> ds(N, vector<int>(N, 0));
      |     ^~~~~~
a.cc:33:5: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:33:19: error: expected primary-expression before 'int'
   33 |     vector<vector<int>> ds(N, vector<int>(N, 0));
      |                   ^~~
a.cc:37:17: error: 'ds' was not declared in this scope
   37 |                 ds[i][j] = 0;
      |                 ^~
a.cc:39:25: error: 'all_es' was not declared in this scope
   39 |                 int c = all_es[i][j];
      |                         ^~~~~~
a.cc:40:17: error: 'ds' was not declared in this scope
   40 |                 ds[i][j] = c == 0 ? INF : 1;
      |                 ^~
a.cc:48:26: error: 'ds' was not declared in this scope; did you mean 'd1'?
   48 |                 int d1 = ds[i][j];
      |                          ^~
      |                          d1
a.cc: In function 'int main()':
a.cc:65:5: error: 'vector' was not declared in this scope
   65 |     vector<vector<int>> all_es(N, vector<int>(N, 0));
      |     ^~~~~~
a.cc:65:5: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:65:19: error: expected primary-expression before 'int'
   65 |     vector<vector<int>> all_es(N, vector<int>(N, 0));
      |                   ^~~
a.cc:71:13: error: 'all_es' was not declared in this scope
   71 |             all_es[i][j] = c - '0';
      |             ^~~~~~
a.cc:74:25: error: 'all_es' was not declared in this scope
   74 |     if (!is_bi_graph(N, all_es)) {
      |                         ^~~~~~
a.cc:78:27: error: 'all_es' was not declared in this scope
   78 |     int d = calc_max_d(N, all_es);
      |                           ^~~~~~