Language: C++


// D - Line++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

struct Node {
	vector<int> neighbors;
	bool visited = false;
	int step;
};

int N, X, Y;
Node nodes[2000];
int count[2000];

void bfs(int start) {
	for (int i=0; i<N; i++) {
		nodes[i].visited = false;
		nodes[i].step = -1;
	}
	nodes[start].visited = true;
	nodes[start].step = 0;

	queue<int> search_queue;
	search_queue.push(start);

	while(!search_queue.empty()) {
		// キューから探索対象のノードのインデックスを取り出す
		int i = search_queue.front();
		search_queue.pop();

		int step = nodes[i].step;
		//cout << i << " (" << step << ")" << endl; // **** debug ****

		count[step]++;

		for (int n : nodes[i].neighbors) {
			if (nodes[n].visited) {
				continue; // 探索済みならキューに入れない
			}

			nodes[n].visited = true;
			nodes[n].step = step + 1;
			search_queue.push(n);
		}
	}
}

int main(){
	cin >> N >> X >> Y;

	// i と i+1 を接続
	for (int i=0; i<N-1; i++) {
		nodes[i].neighbors.push_back(i+1);
		nodes[i+1].neighbors.push_back(i);
	}

	// X と Y を接続
	nodes[X-1].neighbors.push_back(Y-1);
	nodes[Y-1].neighbors.push_back(X-1);

	// 各頂点からBSF
	for (int i=0; i<N; i++) {
		//cout << "start: " << i << endl; // **** debug ****
		bfs(i);
	}

	// 2回ずつカウントされるので割って出力
	for (int i=1; i<N; i++) {
		cout << count[i] / 2 << endl;
	}

	return 0;
}

Compiler output:
a.cc: In function 'void bfs(int)':
a.cc:40:17: error: reference to 'count' is ambiguous
   40 |                 count[step]++;
      |                 ^~~~~
In file included from /usr/include/c++/14/algorithm:86,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:4:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:19:5: note:                 'int count [2000]'
   19 | int count[2000];
      |     ^~~~~
a.cc: In function 'int main()':
a.cc:75:25: error: reference to 'count' is ambiguous
   75 |                 cout << count[i] / 2 << endl;
      |                         ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:19:5: note:                 'int count [2000]'
   19 | int count[2000];
      |     ^~~~~