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
#include<cstdio>
#include "kollib.h"
#include "message.h"
using namespace std;
int il_jed,ID,wiesz,N;
int SAM(){
	int T[N+1];
	int ojc,syn,wnuk,a,b, wyn;
	ojc=1;
	syn=FirstNeighbor(1);
	T[1]=0;
	int od=0;
	while(syn!=1){
		wnuk=FirstNeighbor(syn);
		od++;
		T[syn]=od;
		if(wnuk==ojc)wnuk=SecondNeighbor(syn);
	}
	int m=NumberOfQueries();
		for(int i=0;i<m;i++){
			a=QueryFrom(i+1);
			b=QueryTo(i+1);
			wyn=b-a;
			if(wyn<0)wyn*=-1;
			if(wyn>N-wyn)wyn=N-wyn;
			printf("%d\n",wyn);
		}
	return 0;
	}
int main(){
	ID=MyNodeId();
	if(ID!=0) return 0;
	return SAM();
	}