# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
958770 | teo_thrash | 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"
vector<int> nbrs[MAX_N];
int curr=0;
int start(int N, bool A[MAX_N][MAX_N]){
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
if(A[i][j]){
nbrs[i].pb(j);
nbrs[j].pb(i);
}
}
}
return 0;
}
int dfs(int x, int y, int to){
if(x==to) return 0;
for(auto u: nbrs[x]){
if(u==y) continue;
int nas = dfs(u, x, to);
if(nas!=-1){
return 1+nas;
}
}
return -1;
}
int nextMove(int R){
int dist = dfs(curr, -1, R);
for(auto u: nbrs[curr]){
if(dfs(u, -1, R)==dist-1){
return curr=u;
}
}
return 0;
}