QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#512 | #310313 | #5446. 琪露诺的符卡交换 | zyxawa | zyxawa | Failed. | 2024-01-21 10:53:30 | 2024-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.
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#310313 | #5446. 琪露诺的符卡交换 | zyxawa | 100 ✓ | 28ms | 6064kb | C++23 | 1023b | 2024-01-21 10:53:11 | 2024-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;
}