1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <random>
#include "kollib.h"
#include "message.h"

int M;
int I;
int N;
int Q;
int QF[201];
int QT[201];

int next(int current,int last)
{
 int first = FirstNeighbor(current);
 if(first == last)
   return SecondNeighbor(current);
 return first;
}

int A[10001];

void alone()
{
 int current = 1;
 int last = FirstNeighbor(current);
 A[current] = 0;
 for(int i=1;i<N;i++)
 {
  int j = next(current,last);
  A[j] = i;
  last = current;
  current = j;
 }
 for(int i=0;i<Q;i++)
 {
  int j = std::abs(A[QF[i]]-A[QT[i]]);
  std::cout << std::min(j,N-j) << std::endl;
 }
}

int main()
{
 std::cin.sync_with_stdio(false);
 I = MyNodeId();
 M = NumberOfNodes();
 N = NumberOfStudents();
 Q = NumberOfQueries();

 if(Q == 0)
  return 0;

 for(int i=0;i<Q;i++)
 {
  QF[i] = QueryFrom(i+1);
  QT[i] = QueryTo(i+1);
 }

  if(!I)
   alone();
  return 0;
}