Language: C++

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//constants
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1<<28;


struct edge { int to, cost; };
typedef pair<int, int> P;
vector< vector<edge> > G1;
vector< vector<edge> > G2;
vector<int> d;

void dijkstra(int s, int N, vector< vector<edge> > G) {
    priority_queue<P, vector<P>, greater<P> > que;
    d.resize(N, INF);
    REP(i, N)
        d[i] = INF;
    d[s] = 0;
    que.push(P(0, s));
    //cout << "D" << endl;
    while (!que.empty()) {
        P p = que.top(); que.pop();
        //cout << p.second << " " << p.first << endl;
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            //cout << "UPDATE * " << v << " TO " << e.to << " " << d[e.to] << " " << d[v]+e.cost << endl;
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    //cout << "DEND" << endl;
}

int main(int argc, char **argv) {
    int N, K, L;
    cin >> N >> K >> L;
    G1.resize(N);
    G2.resize(N);

    REP(i, K){
        int f, t;
        cin >> f >> t;
        edge e1 = {t-1, 1};
        edge e2 = {f-1, 1};
        G1[f-1].push_back(e1);
        G1[t-1].push_back(e2);
    }
    REP(i, L){
        int f, t;
        cin >> f >> t;
        edge e1 = {t-1, 1};
        edge e2 = {f-1, 1};
        G2[f-1].push_back(e1);
        G2[t-1].push_back(e2);
    }

    //cout << "HOGE" << endl;
    //REP(i, N){
    //    cout << i << endl;
    //    REP(j, G1[i].size()){
    //        cout << "    " << G1[i][j].to << endl;
    //    }
    //}

    //cout << "HOGE" << endl;
    //REP(i, N){
    //    cout << i << endl;
    //    REP(j, G2[i].size()){
    //        cout << "    " << G2[i][j].to << endl;
    //    }
    //}

    //cout << "HOGE" << endl;

    vector < vector <int> > ans1;
    ans1.resize(N);
    REP(i, N)
        ans1[i].resize(N, INF);

    REP(i, N){
        dijkstra(i, N, G1);
        REP(j, N)
            ans1[i][j] = d[j];
        cout << i << endl;
        REP(j, N)
            cout << "    " << d[j] << endl;
    }

    vector < vector<int> > ans2;
    ans2.resize(N);
    REP(i, N)
        ans2[i].resize(N, INF);

    REP(i, N){
        dijkstra(i, N, G2);
        REP(j, N)
            ans2[i][j] = d[j];
        cout << i << endl;
        REP(j, N)
            cout << "    " << d[j] << endl;
    }

    REP(i, N)
        REP(j, N)
        if (ans1[i][j] != INF && ans2[i][j] != INF)
            ans[i]++;

    vector<int> ans;
    ans.resize(N, 0);

    REP(i, N)
        cout << ans[i] << " ";
    cout << endl;

    return 0;

}



Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:134:13: error: 'ans' was not declared in this scope; did you mean 'ans2'?
  134 |             ans[i]++;
      |             ^~~
      |             ans2