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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "message.h"
#include "kollib.h"
#include <cstdio>
#include <vector>


using namespace std;

vector <int> wynik;


int main()
{
    int n, t, a, b, c, d, wyn;
    
    n = NumberOfStudents();
    t = NumberOfQueries();    
    
    
    int poczatek = (MyNodeId() * t) / NumberOfNodes();
    int koniec = ((MyNodeId() + 1) * t) / NumberOfNodes();
    
    
    for(int i = poczatek; i < koniec; i++)
      {
          a = QueryFrom(i + 1);
          b = QueryTo(i + 1);
          
          
          c = a;
          d = a;
          wyn = 0;
          
          
          while(c != b)
            {
               if(FirstNeighbor(c) != d)
                 {
                    d = c;
                    c = FirstNeighbor(c);
                 }
               
               else
                 {
                    d = c;
                    c = SecondNeighbor(c);
                 }
               
               wyn++;
            }
          
          wynik.push_back(min(wyn, n - wyn));
      }
    
    if(MyNodeId() > 0)
      {
           PutInt(0, wynik.size());
           
           for(int j = 0; j < wynik.size(); j++)
             PutInt(0, wynik[j]);
          
           Send(0);
      }
    
    else
      {
    
          for(int i = 1; i < NumberOfNodes(); i++)
            {
               Receive(i);
               a = GetInt(i);
               
               for(int j = 0; j < a; j++)
                 { 
                     wynik.push_back(GetInt(i));
                 }
            }
          
          for(int i = 0; i < wynik.size(); i++)
            {
                printf("%d\n", wynik[i]);
            }
      }
    
    
    return 0;
}