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;
const int MAXN=505;
int gg[MAXN][MAXN];
vector<int> g[MAXN];
int dist[MAXN][MAXN];
int marc[MAXN][MAXN];
int n, cur;
void bfs(int ori) {
queue<int> qu; qu.push(ori);
dist[ori][ori]=0;
while(qu.size()) {
int cur=qu.front(); qu.pop();
for(auto viz : g[cur]) {
if(dist[ori][viz]!=-1) continue;
qu.push(viz);
dist[ori][viz]=dist[ori][cur]+1;
}
}
}
int start(int N, bool V[MAX_N][MAX_N])
{
n=N;
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
gg[i][j]=V[i][j];
if(gg[i][j]) g[i].push_back(j);
}
}
memset(dist, -1, sizeof(dist));
for(int i=0; i<n; i++) bfs(i);
//for(int i=0; i<n; i++) for(int j=i; j<n; j++) printf("dist %d %d > %d\n", i, j, dist[i][j]);
cur=0;
return 0;
}
int nextMove(int R)
{
int melhor=cur; int menor=n;
for(auto viz : g[cur]) {
if(marc[viz][R]) continue;
if(dist[viz][R]<=menor) melhor=viz, menor=dist[viz][R];
}
cur=melhor;
marc[cur][R]=1;
return cur;
}
# | 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... |