# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
302386 | dantoh000 | Cop and Robber (BOI14_coprobber) | C++14 | 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>
#include "coprobber.h"
using namespace std;
typedef tuple<int,int,int> iii;
bool state[505][505][2];
int num[505][505];
int ct[505];
int G[505][505];
int pa[505][505];
int st = -1;
queue<iii> Q;
int start(int N, bool A[MAX_N][MAX_N])
{
for (int i = 0; i < N; i++){
for (int j = 0; j < N; j++){
G[i][j] = A[i][j];
ct[i] += G[i][j];
}
state[i][i][0] = state[i][i][1] = 1;
pa[i][i][0] = pa[i][i][1] = -1;
Q.push({i,i,0});
Q.push({i,i,1});
}
while (Q.size()){
int x, y, flag;
tie(x,y,flag) = Q.front(); Q.pop();
if (flag){
for (int i = 0; i < n; i++){
if (G[x][i] || i==x){
if (state[i][y][0]) continue;
pa[i][y] = x;
state[i][y][0] = true;
Q.push_back({i,y,0});
}
}
}
else{
for (int i = 0; i < n; i++){
if (G[i][y]){
num[x][i]++;
if (num[x][i] == cnt[i]){
state[x][i][1] = true;
Q.push({x,i,1});
}
}
}
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (state[i][j][0] == false) break;
if (j == n-1) st = i;
}
}
return st;
}
int nextMove(int R)
{
return st = pa[st][R];
}