Submission #419497

#TimeUsernameProblemLanguageResultExecution timeMemory
419497den_tarCop and Robber (BOI14_coprobber)C++14
16 / 100
58 ms1744 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...