# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
34254 | imaxblue | 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>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
int n, m, dp[505][505][2], nxt[505][505];
bool u[505][505][2];
vector<int> v[505];
void dfs(int N, int M, bool B){
if (u[N][M][B]) return;
u[N][M][B]=1;
if (N==M){
dp[N][M][B]=1;
return;
}
if (B){
fox(l, v[N].size()){
dfs(v[N][l], M, !B);
dp[N][M][B]|=dp[v[N][l]][M][!B];
if (dp[v[N][l]][M]!=0) nxt[N][M]=v[N][l];
}
} else {
int t=1;
fox(l, v[M].size()){
dfs(N, v[M][l], !B);
t&=dp[N][v[M][l]][!B];
}
dp[N][M][B]=0;
}
}
int start (int N, bool A[][]){
fox(l, N){
fox(l2, N){
if (A[l][l2]) v[l].pb(l2);
}
}
fox(l, N){
bool f=1;
fox(l2, N){
dfs(l, l2, 0);
if (dp[l][l2][0]==0){
f=0;
break;
}
}
if (f){
return N;
}
}
return -1;
}
int nextMove(int R){
m=R;
n=nxt[n][m];
return n;
}