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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "kollib.h"
#include "message.h"

#include<iostream>
#include<vector>
//#include<string>
//#include<map>
//#include<complex>
//#include<stack>
//#include<list>
//#include<bitset>
//#include<set>
//#include<iterator>
#include<cmath>
//#include<queue>
//#include<time.h>
//#include<string.h>
//#include<fstream>
//#include<sstream>
#include<algorithm>

using namespace std;

#define REP( x,y ) for( int x=0; x<(y); x++ )
#define FORD( x,y,z ) for( int x=y; x>=(z); x-- )
#define FOR(x,b,e) for( int x = b; x <= (e); ++x )
#define SIZE(v) (int)v.size()
#define ALL(c) c.begin(),c.end()
#define VAR(v,n) __typeof(n) v=(n)
#define FOREACH(i,c) for( VAR(i,c.begin());i!=c.end();++i )
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
#define WRITE( V ){ FOREACH(it,V) cout << *it << ", "; cout << endl; }
#define WRITE_ALL(V,s,t) { cout << s << endl;  REP( i,SIZE(V) ){ cout  << i+1 << " ---- ";  FOREACH(it,V[i]) cout << *it+t << ", "; cout << endl;     } }
#define WRP(p) p.ST << " " << p.ND
#define CLEAR( dst,quant ) memset( dst,0, (quant)*sizeof( __typeof(*dst) ) );
#define WAR if( show_help )
#define ENDL(x) REP(crow,(x)) cout << endl;

const bool show_help = 1;
const int INF = 1000000001;
int N,M,K,a,b,c,y,t,w,l_zest;
const long double EPS = 1e-11;
typedef vector<double> VD;
typedef pair<double,int> PDI;
typedef pair<double, double> PDD;
typedef vector<bool> VB;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef pair<int,int> PII;
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<PII> VPII;


int nodes, myinst; // ilosc wierzcholkow oraz numer mojej instancji



void solveSmall(){
	VI V;
	int beg = FirstNeighbor(1);
	V.PB(1);
	V.PB(beg);
	
	while( V[ SIZE(V)-1 ] != V[0] ){ // po tym whilu powinienem miec wszystkich juz w wektorze V
		if( FirstNeighbor( V[ SIZE(V)-1 ] ) != V[ SIZE(V)-2 ] ) V.PB( FirstNeighbor( V[ SIZE(V)-1 ] ) );
		else V.PB( SecondNeighbor( V[ SIZE(V)-1 ] ) );
	}
	V.pop_back(); // musze usunac ostatni element, bo to jest tak naprawde pierwszy(zerowy) element...
	
	VI poz(SIZE(V));
	REP(i,SIZE(poz)) poz[ V[i]-1 ] = i; // osoba o numerze V[i] jest w V na miejscu i
	
	int M = NumberOfQueries();
	int a,b,dist;
	FOR(i,1,M){
		a = QueryFrom(i);
		b = QueryTo(i);
		dist = abs( poz[a-1] - poz[b-1] );
		dist = min( dist, SIZE(V) - dist );
		cout << dist << endl;
	}
	
	
}


int main(){
	
	ios_base::sync_with_stdio(0);
	
	N = NumberOfStudents();
	nodes = NumberOfNodes();
	myinst = MyNodeId();
	
	if( N <= 100000 ){ // dla malych danych moge to zrobic recznie, ale tylko w jednej, pierwszej instancji
		if( myinst == 0 ) solveSmall();
	}
	else{ // dla wiekszych niech juz to bedzie rozproszone
		while(true);
		int m = myinst * N / nodes; // srodek mojego przedzialu	
		int t = 0; // wskaznik rozchodzenia sie
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	}
		
	return 0;
}