QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#512#310313#5446. 琪露诺的符卡交换zyxawazyxawaFailed.2024-01-21 10:53:302024-01-21 10:53:30

Details

Extra Test:

Accepted
time: 1ms
memory: 3752kb

input:

1
1
1

output:

0

result:

ok your solution is correct.

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#310313#5446. 琪露诺的符卡交换zyxawa100 ✓28ms6064kbC++231023b2024-01-21 10:53:112024-01-21 10:53:12

answer

#include<bits/stdc++.h>
using namespace std;
int t,n,x,a[201][201],match[201],vis[201];
vector <int> rest[201][201],G[201];
bool dfs(int x,int k){
	for(auto y:G[x]){
		if(vis[y]!=k){
			vis[y]=k;
			if(!match[y]||dfs(match[y],k)){
				match[y]=x;
				return true;
			}
		}
	}
	return false;
}
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			G[i].clear();
			for(int j=1;j<=n;j++) rest[i][j].clear();
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				scanf("%d",&x);
				rest[i][x].push_back(j);
				G[i].push_back(x);
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++) vis[j]=match[j]=0;
			for(int j=1;j<=n;j++) dfs(j,j);
			for(int j=1;j<=n;j++){
				int x=match[j];
				a[x][i]=rest[x][j].back();
				rest[x][j].pop_back();
				G[x].erase(find(G[x].begin(),G[x].end(),j));
			}
		}
		printf("%d\n",n*(n-1)/2);
		for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) printf("%d %d %d %d\n",i,a[i][j],j,a[j][i]);
	}
	return 0;
}