#include "coprobber.h"
#include <bits/stdc++.h>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
vector<vector<int>> neigh;
vector<vector<int>> visited;
vector<vector<int>> nxt;
int pos=0;
int dfs(int p, int b, bool t){
if(visited[p][b]>0) return visited[p][b];
visited[p][b]=1;
if(t){
int mx=0;
int mxI=0;
for (auto np : neigh[p])
{
int d=dfs(np, b, false);
if(d>mx) {mx=d; mxI=np; }
}
nxt[p][b]=mxI;
return visited[p][b]=mxI;
}else{
int mn=4;
for (auto nb : neigh[b])
{
int d=dfs(nb, b, false);
if(d<mn) {mn=d; }
}
return visited[p][b]=mn;
}
}
int start(int N, bool A[MAX_N][MAX_N])
{
visited.resize(N,vector<int>(N,0));
neigh.resize(N);
nxt.resize(N,vector<int>(N,0));
for (int i = 0; i < N; i++)
{
visited[i][i]=3;
for (int j = 0; j < N; j++)
{
if(A[i][j]) { neigh[i].push_back(j); neigh[j].push_back(i); }
}
}
for (int i = 0; i < N; i++)
{
bool b=true;
for (int j = 0; j < N; j++)
{
if(i==j) continue;
if(dfs(i,j,0)!=3) b=false;
}
if(b){
pos=i;
return i;
}
}
return -1;
}
int nextMove(int R)
{
return pos=nxt[pos][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... |