# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
346366 | saleh | Cop and Robber (BOI14_coprobber) | C++17 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
#define ft first
#define sd second
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> tip;
const int MAXN = 500 + 3;
int st, dd[MAXN], d[MAXN][MAXN], par[MAXN][MAXN];
queue<tip> q;
bitset<MAXN> mark[2 + 1][MAXN];
int start(int n, int *a[]) {
for (int i = 0; i < 2; i++) for (int j = 0; j < n; j++) {
q.push({i, {j, j}});
mark[i][j][j] = true;
}
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dd[i] += a[i][j];
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) d[i][j] = dd[j];
while (!q.empty()) {
tip x = q.front();
q.pop();
if (x.ft == 0) {
for (int i = 0; i < n; i++) if (a[i][x.sd.sd] && --d[x.sd.ft][i] == 0) {
q.push({1, {x.sd.ft, i}});
mark[1][x.sd.ft][i] = true;
}
} else {
for (int i = 0; i < n; i++) if (i == x.sd.ft || a[i][x.sd.ft] == 1) if (!mark[0][i][x.sd.sd]) {
q.push({0, {i, x.sd.sd}});
par[i][x.sd.sd] = x.sd.ft;
mark[0][i][x.sd.sd] = true;
}
}
}
for (int i = 0; i < n; i++) {
bool z = true;
for (int j = 0; j < n; j++) z &= mark[0][i][j];
if (z) return st = i;
}
return -1;
}
int nextMove(int r) {
return st = par[st][r];
}
int main() {
return 0;
}