Language: C++

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <vector>
#define INF 0x3f3f3f3f

using namespace std;
const int maxn = 2005;
int dis[maxn], pre[maxn];
int len[2005][2005];
int cnt1[2005];
struct Edge//边 
{
    int u, v, w;
    Edge() {};
    Edge(int uu, int vv, int ww): u(uu), v(vv), w(ww) {};
};

vector<Edge> edges;//边数组 
vector<int> G[maxn];//存储每个节点对应的边的序号 


void init(int nn)//清理 
{
    for(int i = 0; i <= nn; i++)
        G[i].clear();
    edges.clear();
}

void AddEdge(int uu, int vv, int ww)//加边 
{
    edges.push_back(Edge(uu, vv, ww));
    int edgenum = edges.size();
    G[uu].push_back(edgenum - 1);
}

struct node//优先队列优化，dis小的先出队 
{
    int u, d;
    node() {};
    node(int uu, int dd): u(uu), d(dd) {};
    friend bool operator < (node a, node b)
    {
        return a.d > b.d;
    }
};

void dijkstra(int s)
{
    priority_queue<node> q;
    memset(dis, INF, sizeof(dis));//dis初始化为INF 
    dis[s] = 0;
    q.push(node(s, dis[s]));
    while(!q.empty())
    {
        node cur = q.top();
        q.pop();
        int from = cur.u;
        if(cur.d != dis[from])//减少了vis数组，表示该节点被取出来过 
            continue;
        for(int i = 0; i < G[from].size(); i++)//更新所有集合外点到集合的dis 
        {
            Edge e = edges[G[from][i]];
            if(dis[e.v] > dis[e.u] + e.w)
            {
                dis[e.v] = dis[e.u] + e.w;
                pre[e.v] = from;//存储父节点 
                q.push(node(e.v, dis[e.v]));//将有更新的dis加入到队列中 
            }
        }
    }
}
int main()
{
    int n, m;
    scanf("%d", &n);
        init(n);
            int u, v, w;
            for(int i = 1;i <= n;i++){
            	for(int j= 1;j <= n;j++){
            		AddEdge(i,j,abs(i-j));
				}
			}
            scanf("%d%d", &x, &y);
            AddEdge(x,y,1);
            AddEdge(x, y, 1);
        }
        for(int i = 1;i <= n;i++){
        	dijkstra(i);
        	for(int ii = 1;ii <= n;ii++)
        	len[i][ii] = dis[ii];
		}
         for(int i = 1;i <=n;i++)
    for(int j = 1;j <=n;j++ )
    cnt1[len[i][j]]++;
    for(int i = 1;i <= n-1;i++)
    cout << cnt1[i] << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:87:28: error: 'x' was not declared in this scope
   87 |             scanf("%d%d", &x, &y);
      |                            ^
a.cc:87:32: error: 'y' was not declared in this scope
   87 |             scanf("%d%d", &x, &y);
      |                                ^
a.cc: At global scope:
a.cc:91:9: error: expected unqualified-id before 'for'
   91 |         for(int i = 1;i <= n;i++){
      |         ^~~
a.cc:91:23: error: 'i' does not name a type
   91 |         for(int i = 1;i <= n;i++){
      |                       ^
a.cc:91:30: error: 'i' does not name a type
   91 |         for(int i = 1;i <= n;i++){
      |                              ^
a.cc:96:10: error: expected unqualified-id before 'for'
   96 |          for(int i = 1;i <=n;i++)
      |          ^~~
a.cc:96:24: error: 'i' does not name a type
   96 |          for(int i = 1;i <=n;i++)
      |                        ^
a.cc:96:30: error: 'i' does not name a type
   96 |          for(int i = 1;i <=n;i++)
      |                              ^
a.cc:97:19: error: 'j' does not name a type
   97 |     for(int j = 1;j <=n;j++ )
      |                   ^
a.cc:97:25: error: 'j' does not name a type
   97 |     for(int j = 1;j <=n;j++ )
      |                         ^
a.cc:99:5: error: expected unqualified-id before 'for'
   99 |     for(int i = 1;i <= n-1;i++)
      |     ^~~
a.cc:99:19: error: 'i' does not name a type
   99 |     for(int i = 1;i <= n-1;i++)
      |                   ^
a.cc:99:28: error: 'i' does not name a type
   99 |     for(int i = 1;i <= n-1;i++)
      |                            ^
a.cc:101:5: error: expected unqualified-id before 'return'
  101 |     return 0;
      |     ^~~~~~
a.cc:102:1: error: expected declaration before '}' token
  102 | }
      | ^