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
#include <cstdio>
#include <cstdlib>
#include <vector>
#include "kollib.h"
#include "message.h"

using namespace std;

int mini(int a, int b) {
    return a > b ? b : a;
}

int main() {
    int n = NumberOfStudents(), m = NumberOfQueries();
    int id = MyNodeId();
    int nodes = NumberOfNodes();
    if (id == 0) {
    vector<int> okrag(n+1);
    okrag[1] = 0;
    int prev = 1;
    int next = FirstNeighbor(1);
    while (next != 1) {
        okrag[next] = okrag[prev] + 1;
        int a = FirstNeighbor(next), b = SecondNeighbor(next);
        if (a != prev) {
            prev = next;
            next = a;
        } else {
            prev = next;
            next = b;
        }
    }
    vector<int> result(m+1, -1);
    for (int i = 1; i <= m; i++) {
        int a = QueryFrom(i), b = QueryTo(i);
        int odl = (okrag[b] > okrag[a]) ? okrag[b] - okrag[a] : okrag[a] - okrag[b];
        odl = mini(odl, n - odl);
        result[i] = odl;
    }
        for (int i = 1; i <= m; ++i) {
            printf("%d\n", result[i]);
        }
    }
    return 0;
}