Language: C++

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"

using namespace std;
const long long int MOD = 1000000007;

long long int N,K;
list <int>edge[2001];
int dis[2001][2001];
int s, e;
bool flag[2001] = {};
queue<int>Q;
int f;
int box[2001];
int bag;
int ans;

int main() {
	cin >> N>>K;
	for (int i = 1; i <= N; i++) {
		flag[i] = true;
	}
	for (int i = 0; i < N-1; i++) {
		cin >> s >> e;
		edge[s].insert(e);
		edge[e].insert(s);
	}
	while(1){
		for (int i = 1; i <= N; i++) {
			box[i] = 0;
			if (flag[i]) {
				
				for (int j = 1; j <= N; j++) {
					if (i != j) {
						dis[i][j] = INT_MAX;
					}
				}
				Q.push(i);
				while (!Q.empty()) {
					f = Q.front();
					for (auto j = edge[f].begin(); j != edge[f].end(); ++j) {
						if (flag[*j]) {
							if (dis[i][*j] > dis[i][f] + 1) {
								dis[i][*j] = dis[i][f] + 1;
								Q.push(*j);
								if (dis[i][*j] > K) {
									box[i]++;
								}
							}
						}
					}
					Q.pop();
				}
				if (box[i])bag++;
			}
		}
		bag = 0;
		for (int i = 1; i <= N; i++) {
			bag = max(bag, box[i]);
		}
		if (bag) {
			ans++;
			for (int i = 1; i <= N; i++) {
				if (box[i] == bag) {
					flag[i] = false;
					break;
				}
			}
		}
		else break;
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:31: error: no matching function for call to 'std::__cxx11::list<int>::insert(int&)'
   32 |                 edge[s].insert(e);
      |                 ~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/list:65,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_list.h:1491:9: note: candidate: 'template<class _InputIterator, class> std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = int; _Alloc = std::allocator<int>]'
 1491 |         insert(const_iterator __position, _InputIterator __first,
      |         ^~~~~~
/usr/include/c++/14/bits/stl_list.h:1491:9: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/list:66:
/usr/include/c++/14/bits/list.tcc:101:5: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator; value_type = int]'
  101 |     list<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/list.tcc:101:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_list.h:1411:7: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator; value_type = int]'
 1411 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_list.h:1411:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_list.h:1430:7: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator]'
 1430 |       insert(const_iterator __p, initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_list.h:1430:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/list.tcc:117:5: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, size_type, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator; size_type = long unsigned int; value_type = int]'
  117 |     list<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/list.tcc:117:5: note:   candidate expects 3 arguments, 1 provided
a.cc:33:31: error: no matching function for call to 'std::__cxx11::list<int>::insert(int&)'
   33 |                 edge[e].insert(s);
      |                 ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_list.h:1491:9: note: candidate: 'template<class _InputIterator, class> std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = int; _Alloc = std::allocator<int>]'
 1491 |         insert(const_iterator __position, _InputIterator __first,
      |         ^~~~~~
/usr/include/c++/14/bits/stl_list.h:1491:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/list.tcc:101:5: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator; value_type = int]'
  101 |     list<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/list.tcc:101:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_list.h:1411:7: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator; value_type = int]'
 1411 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_list.h:1411:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_list.h:1430:7: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator]'
 1430 |       insert(const_iterator __p, initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_list.h:1430:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/list.tcc:117:5: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, size_type, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator; size_type = long unsigned int; value_type = int]'
  117 |     list<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/list.tcc:117:5: note:   candidate expects 3 arguments, 1 provided