Problem:
Score : 400 points

Problem Statement

We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:

For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.

There is an edge between Vertex X and Vertex Y.

For each k=1,2,...,N-1, solve the problem below:

Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.

Constraints

3 \leq N \leq 2 \times 10^3

1 \leq X,Y \leq N

X+1 < Y

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X Y

Output

For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.

Sample Input 1

5 2 4

Sample Output 1

5
4
1
0

The graph in this input is as follows:

There are five pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 1: (1,2)\,,(2,3)\,,(2,4)\,,(3,4)\,,(4,5).

There are four pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 2: (1,3)\,,(1,4)\,,(2,5)\,,(3,5).

There is one pair (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 3: (1,5).

There are no pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 4.

Sample Input 2

3 1 3

Sample Output 2

3
0

The graph in this input is as follows:

Sample Input 3

7 3 7

Sample Output 3

7
8
4
2
0
0

Sample Input 4

10 4 8

Sample Output 4

10
12
10
8
4
1
0
0
0

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main implements Runnable { //クラス名はMain1

	public static void main(String[] args) {
		Thread.setDefaultUncaughtExceptionHandler((t, e) -> System.exit(1));
		new Thread(null, new Main(), "", 1024 * 1024 * 1024).start(); //16MBスタックを確保して実行
	}

	public void run() {
		FastScannerMainD3 sc = new FastScannerMainD3(System.in);

		try {
			int N = sc.nextInt();
			int X = sc.nextInt();
			int Y = sc.nextInt();			

			//隣接リストの作成
			NextList[] arr = new NextList[N];
			for (int i = 0; i < N; i++) {
				NextList nextList = new NextList();
				if (i == 0) {
					nextList.neighbours.add(i + 1);
				} else if (i == N - 1) {
					nextList.neighbours.add(i - 1);
				} else {
					nextList.neighbours.add(i + 1);
					nextList.neighbours.add(i - 1);
				}
				arr[i] = nextList;
			}

			arr[X - 1].neighbours.add(Y - 1);
			arr[Y - 1].neighbours.add(X - 1);

			int[] ans = new int[N];
			Bfs bfs=new Bfs(N);
			int[] each;
			for (int i = 0; i < N; i++) {
				each =bfs.bfsgraph(i,arr,N);
				for (int j = 0; j < each.length; j++) {
					ans[each[j]]++;
				}
			}

			for (int i = 1; i < N; i++) {
				System.out.println(ans[i]/2);
			}			

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

class Bfs {
	PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
	boolean[] visit;
	int[] distance;

	/**
	 * 
	 * @param N　頂点数
	 */
	public Bfs(int N) {
		visit = new boolean[N];
		distance = new int[N];
	}


	public int[] bfsgraph(int start, NextList[] nl,int N) {
		
		pq.offer(start);
		Arrays.fill(visit,false);
		visit[start] = true;
		
		Arrays.fill(distance,Integer.MAX_VALUE);
		distance[start] = 0;

		while(pq.size()>0){
			int loc = pq.poll();
			for(int i: nl[loc].neighbours){
				if(!visit[i]){
					pq.offer(i);
					visit[i] = true;
					distance[i] = distance[loc]+1;
				}else{
					//さらに短い距離が見つかったら再度調査
					if(distance[i] > distance[loc]+1){
						pq.offer(i);
						distance[i] = distance[loc]+1;
					}
				}
			}
		}
		return distance;
	}
}

class NextList {
	ArrayList<Integer> neighbours = new ArrayList<>();
}

//高速なScanner
class FastScannerMainD3 {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScannerMainD3(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}