QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#75319#5446. 琪露诺的符卡交换Coder_Z0 0ms0kbC++141.2kb2023-02-04 20:37:582023-02-04 20:37:59

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-04 20:37:59]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-02-04 20:37:58]
  • 提交

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;
}

详细

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%