#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; set > next_movements(int n, int x, int y, int stepx, int stepy){ set > s; if(x+stepx>=0 && x+stepx=0 && y+stepy=0 && x+stepx=0 && y-stepy=0 && x-stepx=0 && y+stepy=0 && x-stepx=0 && y-stepy=0 && x+stepy=0 && y+stepx=0 && x+stepy=0 && y-stepx=0 && x-stepy=0 && y+stepx=0 && x-stepy=0 && y-stepx> n; vector > solution(n, vector(n)); for(int i=1;i > q; set > seen; map, pair > parent; q.push(pair(0,0)); while(!q.empty()){ pair node = q.front(); q.pop(); if(seen.find(node) !=seen.end()) continue; seen.insert(node); set > siblings = next_movements(n,node.first, node.second,i,j); for(set >::iterator it=siblings.begin();it!=siblings.end();it++){ if(seen.find(*it) == seen.end()){ q.push(*it); parent[*it] = node; } } } int counter = 1; if(seen.find(make_pair(n-1,n-1)) != seen.end()){ pair temp = parent[make_pair(n-1,n-1)]; while(!(temp.first==0 && temp.second==0)){ temp= parent[make_pair(temp.first,temp.second)]; counter++; } }else{ counter = -1; } solution[i-1][j-1] = counter; solution[j-1][i-1] = counter; } } for(int i=0;i