QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#75319 | #5446. 琪露诺的符卡交换 | Coder_Z | 0 | 0ms | 0kb | C++14 | 1.2kb | 2023-02-04 20:37:58 | 2023-02-04 20:37:59 |
Judging History
answer
// 这匈牙利算法不吊打随机化?
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, a, b) for (int i = (a); i <= (b); i ++)
#define dep(i, a, b) for (int i = (a); i >= (b); i --)
using namespace std;
const int N = 205;
mt19937 rnd(1145141);
vector <int> e[N];
int n, a[N][N], ch[N], vis[N];
int ans[N][N];
int dfs(int u) {
for (auto v : e[u]) if ( !vis[v] ) {
vis[v] = 1;
if ( !ch[v] || dfs(ch[v]) ) return ch[u] = v, ch[v] = u, 1;
}
return 0;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T; cin >> T;
while ( T -- ) {
cin >> n;
rep(i, 1, n) rep(j, 1, n) cin >> a[i][j];
rep(_, 1, n) {
memset(ch, 0, sizeof ch);
rep(i, 1, (n << 1)) e[i].clear();
rep(i, 1, n) rep(j, 1, n) if ( a[i][j] )
e[a[i][j] + n].push_back(i), e[i].push_back(a[i][j] + n);
rep(i, 1, n) memset(vis, 0, sizeof vis), dfs(i);
rep(i, 1, n) rep(j, 1, n) if ( ch[i] - n == a[i][j] )
{ a[i][j] = 0, ans[i][_] = j; break; }
}
cout << n * (n - 1) / 2 << '\n';
rep(i, 1, n) rep(j, i + 1, n)
cout << i << ' ' << ans[i][j] << ' ' << j << ' ' << ans[j][i] << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
7 132 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 ...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%