This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///~~~LOTA~~~///
#include "coprobber.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define append push_back
#define add insert
#define nl "\n"
#define ff first
#define ss second
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL)
#define N 500
int r;
int par[N];
int dept[N];
int dist[N][N];
vector<int> g[N];
map<pii,int> x;
void dfs(int v){
for(auto& i:g[v]){
if(dept[i]){
r=max(r,dept[v]-dept[i]);
if(dept[v]-dept[i]==3){
x[{v,par[par[v]]}]=1;
x[{par[par[v]],v}]=1;
x[{par[v],par[par[par[v]]]}]=1;
x[{par[par[par[v]]],par[v]}]=1;
}
}
else{
dept[i]=dept[v]+1;
par[i]=v;
dfs(i);
}
}
}
int start(int n, bool a[N][N]){
for(int i=0;i<n;i++)
for(int j=r=0;j<n;j++)
if(a[i][j]) g[i].append(j);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j) dist[i][j]=0;
else if(a[i][j]) dist[i][j]=1;
else dist[i][j]=N;
}
}
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
for(int k=0;k<n;k++)
dist[i][k]=min(dist[i][k],dist[i][j]+dist[j][k]);
dept[0]=1;
dfs(0);
if(r>3) return -1;
r=0;
return 0;
}
int nextMove(int v){
if(x[{v,r}]) return r;
pii pi={2*N,N};
for(auto& i:g[r])
pi=min(pi,{dist[v][i],i});
r=pi.ss;
return r;
}
# | 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... |