# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
852774 | drkarlicio2107 | 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 "coprobber.h"
#include <bits/stdc++.h>
using namespace std;
int kol [510][510][2];
int st [510][510][2];
queue < pair <int, pair <int, int> > > kju;
int mov [510][510];
int curr;
int start (int n, bool l [510][510]){
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
int uk=0;
for (int k=0; k<n; k++) uk+=l [j][k];
kol [i][j][0]=1;
kol [i][j][1]=uk;
if (i==j){
kju.push ({0, {i, j}});
kju.push ({1, {i, j}});
}
}
}
while (!kju.empty()){
int m=kju.front().first;
int a=kju.front().second.first;
int b=kju.front().second.second;
//cout << m << " " << a << " " << b << endl;
st [m][a][b]=1;
if (m==0){
for (int i=0; i<n; i++){
if (!l [i][b]) continue;
kol [a][i][1]--;
if (kol [a][i][1]==0){
kju.push ({1, {a, i}});
}
}
}
else {
for (int i=0; i<n; i++){
if (!l [i][a]) continue;
kol [i][b][0]--;
if (kol [i][b][0]==0){
kju.push ({0, {i, b}});
mov [i][b]=a;
}
}
}
kju.pop();
}
for (int i=0; i<n; i++){
int uk=0;
for (int j=0; j<n; j++) uk+=st [1][i][j];
if (uk==n) return curr=i;
}
return -1;
}
int nextMove (int x){
return curr=mov [curr][x];
}
int a [510][510];
/*int main(){
int n; cin >> n;
for (int i=0; i<n; i++){
for (int j=0; j<n; j++) cin >> a [i][j];
}
cout << start (n, a) << endl;
while (true){
int x; cin >> x;
if (x==-1) break;
cout << nextMove (x) << endl;
}
return 0;
}*/