Check whether exist a pair i and j,they satisfy xi+di = xj && xj+dj = xi;
Pay attention to Just Right or Red. use Div and Mod can solve it easily;
As we know, there are only two path -- forward and reverse, so we can do DFS from the one-degree nodes (only two nodes).
As their index may be very larger, so I used map<int,int> to do hash.
void dfs(int i)
int sz = mat[i].size()-1, j;
vis[mat[i][j]] = 1;
First, Floyd pretreat the path from I to J, and save the path.
Then get the answer.
The order is a1,a2...ak, K is the number of the leaves, we can assume a0 = ak+1 = 1, the root.
then, answer push_back the path[ai][ai+1].
if the ans.size() > 2*N-1 , cout -1;
else cout the answer.