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>
using namespace std;
//subtask 2
vector<int> adj[501];
int cop = 1;
int vertex2;
int start(int n, bool a[500][500]){
  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++){
      if (a[i][j] == 1){
        adj[i+1].push_back(j+1);
      }
    }
  }
  for (int i = 2; i < n; i++){
    if (adj[i].size() == 2) {
      vertex2 = i;
      break;
    }
  }
  return 0;
}
int nextMove(int r){
  int m = cop%vertex2;
  r++;
  if (r == cop) return r-1;
  if ((r == cop+1 && m != 0) or (r = cop-1 && m != 1) or (r == cop+vertex2) or (r == cop-vertex2)){
    cop = r;
    return r-1;
  }
  if ((r == cop+vertex2+1 && m != 0) or (r == cop+vertex2-1 && m != 1) or (r == cop-vertex2-1 && m != 1) or (r == cop-vertex2+1 && m != 0)){
    return cop-1;
  }
  if (r > cop){
    if (r <= cop+(vertex2-(m)) && m != 0){
      cop++;
      return cop-1;
    }
    if (r < cop+vertex2){
      cop--;
      return cop-1;
    }
    if (r <= cop+vertex2+(vertex2-(m)) && m != 0){
      cop++;
      return cop-1;
    }
    cop+=vertex2;
    return cop-1;
  }
  else{
    if (r > cop-(m) && m != 0){
      cop--;
      return cop-1;
    }
    if (r > cop-vertex2 && m == 0){
      cop--;
      return cop-1;
    }
    if (r > cop-vertex2){
      cop++;
      return cop-1;
    }
    if (r > cop-vertex2-(m) && m != 0){
      cop--;
      return cop-1;
    }
    if (r > cop-(2*vertex2) && m == 0){
      cop--;
      return cop-1;
    }
    cop-=vertex2;
    return cop-1;
  }
}
| # | 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... |