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
#include <iostream>
#include "kollib.h"
#include "message.h"
#include <stdio.h>
using namespace std;

int main() {

	int n = NumberOfQueries();
	int nodes = NumberOfNodes();
	int myId = MyNodeId();
	
	for (int i=1; i<=n; i++)
	{
		if (i % nodes != myId) continue;
		
		int from = QueryFrom(i);
		int to = QueryTo(i);
		
		int result = 0;
		int previous = -1;
		
		while (from != to)
		{
			int neighbor = FirstNeighbor(from);
			if (neighbor == previous)
				neighbor = SecondNeighbor(from);
			
			previous = from;
			from = neighbor;
			result++;
		}
			
		int k = NumberOfStudents();
		if (result > k/2)
			result = k - result;
		
		printf("%d\n",result);
	
	}
}