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;
typedef long long ll;
const ll DIM = 5e2 + 7;
vector<ll> a[DIM];
ll vis[DIM];
ll n,fl;
ll police;
void dfs(ll v,ll p){
vis[v]=1;
for(auto to:a[v]){
if(vis[to]==2 || to==p)continue;
if(vis[to]==1){
fl=1;
return;
}
dfs(to,v);
if(fl==1)return;
}
vis[v]=2;
}
void dfs1(ll v,ll d){
vis[v]=d;
for(auto to:a[v])
if(vis[to]==(-1))dfs1(to,d+1);
}
int start(int N, bool A[MAX_N][MAX_N])
{
n=N;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(A[i][j])a[i].push_back(j);
dfs(0,(-1));
if(fl==1)return -1;
police=0;
return police;
}
int nextMove(int R)
{
for(int i=0;i<n;i++)vis[i]=(-1);
dfs1(R,0);
if(vis[police]>1){
for(auto to:a[police]){
if(vis[to]<vis[police]){
police=to;
break;
}
}
}
return police;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |