Language: C++

#include<iostream>
#include<queue>
#include<vector>
#include<cstdio>
using namespace std;
struct card { int turn; vector<int>a, b, c; };
queue<pair<card, long double>>Q;
int n; card F;
void Swap(int p, int r, card &G) {
	vector<int>J;
	if (p == 0) { for (int i = 0; i < G.a.size(); i++) { if (G.a[i] != r)J.push_back(G.a[i]); }G.a = J; }
	if (p == 1) { for (int i = 0; i < G.b.size(); i++) { if (G.b[i] != r)J.push_back(G.b[i]); }G.b = J; }
	if (p == 2) { for (int i = 0; i < G.c.size(); i++) { if (G.c[i] != r)J.push_back(G.c[i]); }G.c = J; }
	if (G.turn == 0)G.a.push_back(r);
	if (G.turn == 1)G.b.push_back(r);
	if (G.turn == 2)G.c.push_back(r);
	sort(G.a.begin(), G.a.end());
	sort(G.b.begin(), G.b.end());
	sort(G.c.begin(), G.c.end());
	vector<int>K1, K2, K3; int SS[3][101]; for (int i = 0; i < 303; i++)SS[i / 101][i % 101] = 0;
	for (int i = 0; i < G.a.size(); i++)SS[0][G.a[i]]++; for (int i = 0; i < 101; i++)for (int j = 0; j < SS[0][i] % 2; j++) K1.push_back(i);
	for (int i = 0; i < G.b.size(); i++)SS[1][G.b[i]]++; for (int i = 0; i < 101; i++)for (int j = 0; j < SS[1][i] % 2; j++) K2.push_back(i);
	for (int i = 0; i < G.c.size(); i++)SS[2][G.c[i]]++; for (int i = 0; i < 101; i++)for (int j = 0; j < SS[2][i] % 2; j++) K3.push_back(i);
	G.a = K1; G.b = K2; G.c = K3;
}
int main() {
	cin >> n;
	int D;
	cin >> D; for (int j = 0; j < D; j++) { int DD; cin >> DD; F.a.push_back(DD); }
	cin >> D; for (int j = 0; j < D; j++) { int DD; cin >> DD; F.b.push_back(DD); }
	cin >> D; for (int j = 0; j < D; j++) { int DD; cin >> DD; F.c.push_back(DD); }

	sort(F.a.begin(), F.a.end());
	sort(F.b.begin(), F.b.end());
	sort(F.c.begin(), F.c.end());
	vector<int>K1, K2, K3; int SS[3][101]; for (int i = 0; i < 303; i++)SS[i / 101][i % 101] = 0;
	for (int i = 0; i < F.a.size(); i++)SS[0][F.a[i]]++; for (int i = 0; i < 101; i++)for (int j = 0; j < SS[0][i] % 2; j++) K1.push_back(i);
	for (int i = 0; i < F.b.size(); i++)SS[1][F.b[i]]++; for (int i = 0; i < 101; i++)for (int j = 0; j < SS[1][i] % 2; j++) K2.push_back(i);
	for (int i = 0; i < F.c.size(); i++)SS[2][F.c[i]]++; for (int i = 0; i < 101; i++)for (int j = 0; j < SS[2][i] % 2; j++) K3.push_back(i);
	F.a = K1; F.b = K2; F.c = K3;

	F.turn = 0;
	Q.push(make_pair(F, 1));
	long double sum = 0;
	while (!Q.empty()) {
		card G = Q.front().first; long double H = Q.front().second; Q.pop();
		if (G.a.size() == 0 && G.b.size() != 0 && G.c.size() == 0)sum += H;
		if (G.a.size() + G.b.size() + G.c.size() == 1)continue;
		if (H < 1e-9)continue;
		sort(G.a.begin(), G.a.end());
		sort(G.b.begin(), G.b.end());
		sort(G.c.begin(), G.c.end());
		int A = 0; bool OK = true;
		if (G.turn == 0) {
			if (G.a.size() == 0)OK = false;
			if (G.c.size() >= 1)A = 2; else A = 1;
		}
		if (G.turn == 1) {
			if (G.b.size() == 0)OK = false;
			if (G.a.size() >= 1)A = 0; else A = 2;
		}
		if (G.turn == 2) {
			if (G.c.size() == 0)OK = false;
			if (G.b.size() >= 1)A = 1; else A = 0;
		}
		if (OK == false) { G.turn = (G.turn + 1) % 3; Q.push(make_pair(G, H)); continue; }
		if (A == 0) {
			for (int i = 0; i < G.a.size(); i++) {
				card I = G; vector<int>J;
				Swap(0, G.a[i], I); I.turn = (I.turn + 1) % 3;
				Q.push(make_pair(I, H / (long double)G.a.size()));
			}
		}

		if (A == 2) {
			for (int i = 0; i < G.c.size(); i++) {
				card I = G; vector<int>J;
				Swap(2, G.c[i], I); I.turn = (I.turn + 1) % 3;
				Q.push(make_pair(I, H / (long double)G.c.size()));
			}
		}

		if (A == 1) {
			bool FF[101]; for (int i = 0; i <= 100; i++)FF[i] = false;
			if (G.turn == 0) {
				for (int i = 0; i < G.a.size(); i++)FF[G.a[i]] = true;
			}
			if (G.turn == 2) {
				for (int i = 0; i < G.c.size(); i++)FF[G.c[i]] = true;
			}
			int TT = -1;
			for (int i = 0; i < G.b.size(); i++) {
				if (FF[G.b[i]] == true) { TT = G.b[i]; break; }
			}
			if (TT == -1)TT = G.b[0];
			Swap(1, TT, G); G.turn = (G.turn + 1) % 3;
			Q.push(make_pair(G, H));
		}
	}
	printf("%.20Lf\n", 1.0l - sum);
	return 0;
}

Compiler output:
a.cc: In function 'void Swap(int, int, card&)':
a.cc:17:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   17 |         sort(G.a.begin(), G.a.end());
      |         ^~~~
      |         short
a.cc: In function 'int main()':
a.cc:33:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   33 |         sort(F.a.begin(), F.a.end());
      |         ^~~~
      |         short