This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "coprobber.h"
#include <bits/stdc++.h>
using namespace std;
using ari3 = array<int, 3>;
int nxt[500][500], cur = -1;
int start(int N, bool A[500][500]) {
queue<ari3> qu;
bool cw[N][N][2] = {};
int deg[N][N] = {};
for (int i = 0; i < N; i++) {
cw[i][i][0] = true;
qu.push({i, i, 0});
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
deg[i][j] += A[j][k];
}
}
}
while (qu.size()) {
auto [i, j, m] = qu.front();
qu.pop();
for (int k = 0; k < N; k++) {
if (m && A[j][k]) {
if (cw[i][k][0]) continue;
if (!--deg[i][k]) {
cw[i][k][0] = true;
qu.push({i, k, 0});
}
} else if (!m && (A[i][k] || i == k)) {
if (cw[k][j][1]) continue;
cw[k][j][1] = true;
qu.push({k, j, 1});
nxt[k][j] = i;
}
}
}
for (int i = 0; i < N; i++) {
bool can = true;
for (int j = 0; j < N; j++) {
can &= cw[i][j][1];
}
cur = can ? i : cur;
}
return cur;
}
int nextMove(int r) {
return cur = nxt[cur][r];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |