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
#include "kollib.h"

#ifdef _VSCHECK
#include "..\message.h"
#else
#include "message.h"
#endif

#include <map>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

long long nodes, students, queries, myPID;

long long getDistance(long long a, long long b)
{
	return min(abs(b - a), students - abs(b - a));
}



void ImMaster()
{
	queue<pair<long long, long long> >Q;
	map<long long, long long> Values;
	for (long long i = 1; i <= queries; i++)
	{
		long long from = QueryFrom(i), to = QueryTo(i);
		Values[from] = -1;
		Values[to] = -1;
		Q.push(make_pair(from, to));
	}
	long long poz = 1, prev = 1;
	for (long long i = 1; i <= students; i++)
	{
		if (Values[poz] == -1)
		{
			Values[poz] = i;
		}
		long long tmp = FirstNeighbor(poz);
		if (tmp == prev)
			tmp = SecondNeighbor(poz);
		prev = poz, poz = tmp;
	}
	while (!Q.empty())
	{
		cout << getDistance(Values[Q.front().first], Values[Q.front().second]) << endl;
		Q.pop();
	}
}

void ImNigga()
{

}

int main() {
	nodes = NumberOfNodes(), students = NumberOfStudents(), queries = NumberOfQueries(), myPID = MyNodeId();
	if (myPID == 0) ImMaster();
	else  ImNigga();
	return 0;
}