# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
841825 | manizare | 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>
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define int long long
using namespace std ;
#include "coprobber.h"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 500 + 10 , maxk=1002 , sq = 333 , lg = 20 , K = 0, inf = 1e18+10 , mod = 1e9 + 7 ;
int cnt = 0 , n , dis[maxn] , par[maxn] , st[maxn] , en[maxn] , cur = 0 ;bool c[maxn][maxn] ;
vector <int> G[maxn] ;
void dfs(int v , int p = -1){
st[v] = cnt ; cnt++;
for(int i =0 ; i < G[v].size() ; i++){
int u = G[v][i] ;
if(u== p)continue ;
dis[u] = dis[v] + 1;
dfs(u , v) ;
}
en[v] = cnt ; cnt ++ ;
}
int start(int N , bool f[maxn][maxn]){
for(int i = 0 ; i < N ; i++){
for(int j =0 ; j < N; j++){
if(f[i][j])G[i].pb(j) ;
}
}
n = N ;
dfs(0) ;
return 0;
}
int ch(int v , int u){
if(st[u] >= st[v] && en[v] >= en[u]){
return 1;
}
return 0 ;
}
int nextMove(int v){
if(dis[v]-1 == dis[cur])return cur ;
for(int i =0 ; i < G[cur].size() ; i++){
int u = G[cur][i] ;
if(ch(u, v) && ch(cur , u)){
cur = u;
break ;
}
}
return cur ;
}
/*
signed main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int m ;
cin >> n >>m ;
for(int i =1;i <= m ; i++){
int v , u ;
cin >> v >> u ;
c[v][u] = c[u][v] = 1;
}
int cc = start(n , c) ;
cout << cc << endl ;cout.flush();
cout.flush() ;
if(cc == -1)return 0;
while(1){
int t ;
cin >> t;
if(t == cc)return 0 ;
cc = nextMove(t) ;
cout << cc << endl ;cout.flush() ;
}
}
*/