Language: C++

#include <stdio.h>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

vector<int> G[2020]; vector<pair<int, int> > K[2020],B[2020];
int N,M,P[2020],D[2020],u[2020],v[2020];
int chk[2020],col[2020];

void go(int x, int l)
{
	P[x] = l;
	D[x] = D[l] + 1;
	for (int y : G[x]) if (l != y) go(y,x);
}

int main()
{
	scanf ("%d %d",&N,&M);
	for (int i=1;i<N;i++){
		int x,y; scanf ("%d %d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	go(1,0);

	for (int i=0;i<M;i++){
		scanf ("%d %d",&u[i],&v[i]);
		int x = u[i], y = v[i];
		while (x != y){
			if (D[x] < D[y]){
				K[y].push_back({i,1});
				y = P[y];
			}
			else{
				K[x].push_back({i,0});
				x = P[x];
			}
		}
	}

	int ans = 0;
	for (int i=2;i<=N;i++){
		ans += min(2u,K[i].size());
		if (K[i].size() >= 2){
			int x = K[i][0].first, y = K[i][1].first, d = (K[i][0].second + K[i][1].second + 1) % 2;
			B[x].push_back({y,d});
			B[y].push_back({x,d});
		}
	}

	for (int i=0;i<M;i++) if (!chk[i]){
		queue<int> Q; Q.push(i); chk[i] = 1;
		while (!Q.empty()){
			int x = Q.front(); Q.pop();
			for (auto &p : B[x]){
				int y = p.first, c = (col[x] + p.second) % 2;
				if (!chk[y]){
					Q.push(y); chk[y] = 1; col[y] = c;
				}
				else{
					if (col[y] != c) fprintf(stderr,"?");
				}
			}
		}
	}

	printf ("%d\n",ans);
	for (int i=0;i<M;i++){
		if (col[i]) printf ("%d %d\n",v[i],u[i]);
		else printf ("%d %d\n",u[i],v[i]);
	}

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:45:27: error: no matching function for call to 'min(unsigned int, std::vector<std::pair<int, int> >::size_type)'
   45 |                 ans += min(2u,K[i].size());
      |                        ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:62,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:45:27: note:   deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'})
   45 |                 ans += min(2u,K[i].size());
      |                        ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:45:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
   45 |                 ans += min(2u,K[i].size());
      |                        ~~~^~~~~~~~~~~~~~~~