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

int main(){
	ios_base::sync_with_stdio(0);
	int queries = NumberOfQueries();
	int time=-1;
	for(int i=MyNodeId()+1;i<=queries;i+=NumberOfNodes()){
		//int next= QueryFrom(i);
		//licz odleglosci
		map<int,int> odleglosc;
		//
		vector<int> queryy;
		vector<int> found;
		queryy.push_back(QueryFrom(i));
		int to = QueryTo(i);
		//pierwsza odleglosc wpisz
		odleglosc[queryy.front()]=0;
		bool brejk=false;
		while(!brejk){
			int first = FirstNeighbor(queryy.front());
			int second = SecondNeighbor(queryy.front());
			if(queryy.front()==to){
				brejk=true;
			}
			bool everfound1=false;
			bool everfound2=false;
			for(int j=0;j<found.size() && (!everfound1||!everfound2);j++){
				if(found[j]==first) everfound1=true;
				if(found[j]==second) everfound2=true;
			}
			if(!everfound1){
				queryy.push_back(first);
				odleglosc[first]=odleglosc[queryy.front()]+1;
			}
			if(!everfound2){
				queryy.push_back(second);
				odleglosc[second]=odleglosc[queryy.front()]+1;
			}
			found.push_back(queryy.front());
			queryy.erase(queryy.begin());
		}
		time=odleglosc[to];
		
	}
	if(MyNodeId() > 0){
		PutInt(0, time);
		Send(0);
	}else{//mynodeid ==0
		cout<<time<<endl;
		for (int instancja = 1; instancja < NumberOfNodes(); ++instancja) {
			Receive(instancja);
			int get=GetInt(instancja);
			if(get!=-1){
				cout<<get;
				if(instancja+1!=NumberOfNodes()){
					cout<<endl;
				}
			}
		}
	}
	return 0;
}