# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1053253 | user736482 | Cop and Robber (BOI14_coprobber) | C++17 | 26 ms | 1800 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>
#include<coprobber.h>
using namespace std;
vector<int> sasiad[507];
int akpos;
int licz;
int n,lastr=-1;
int start(int N,bool a[][500]){
n=N;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(a[i][j]){
sasiad[i].push_back(j);
sasiad[j].push_back(i);
licz++;
}
}
}
return 0;
}
int nextMove(int r){
if(licz==n-1){
bool odw[507];
int pop[507];
for(int i=0;i<507;i++)
odw[i]=0;
odw[akpos]=1;
pop[akpos]=akpos;
queue<int>q;
q.push(akpos);
while(!q.empty()){
int pom=q.front();
q.pop();
for(int i=0;i<sasiad[pom].size();i++){
if(!odw[sasiad[pom][i]]){
odw[sasiad[pom][i]]=1;
pop[sasiad[pom][i]]=pom;
q.push(sasiad[pom][i]);
}
}
}
while(pop[r]!=akpos)
r=pop[r];
akpos=r;
return r;
}
for(int i=0;i<sasiad[akpos].size();i++){
if(sasiad[akpos][i]==r){
return r;
}
}
for(int i=0;i<sasiad[akpos].size();i++){
if(sasiad[akpos][i]==r+5 || sasiad[akpos][i]==r-5 || sasiad[akpos][i]==r-3 || sasiad[akpos][i]==r+3){
akpos=sasiad[akpos][i];
return akpos;
}
}
bool odw[507];
int pop[507];
for(int i=0;i<507;i++)
odw[i]=0;
odw[akpos]=1;
pop[akpos]=akpos;
queue<int>q;
q.push(akpos);
while(!q.empty()){
int pom=q.front();
q.pop();
for(int i=0;i<sasiad[pom].size();i++){
if(!odw[sasiad[pom][i]]){
odw[sasiad[pom][i]]=1;
pop[sasiad[pom][i]]=pom;
q.push(sasiad[pom][i]);
}
}
}
while(pop[r]!=akpos)
r=pop[r];
akpos=r;
return r;
}
Compilation message (stderr)
# | 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... |