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

using namespace std;

int main()
{
    int x;
    if(MyNodeId==0)
    {for(int i=1;i<=NumberOfQueries();i++)
    {
        x=1;
        int a1=FirstNeighbor(QueryFrom(i));
        int a2=SecondNeighbor(QueryFrom(i));
        int tmp1=QueryFrom(i);
        int tmp2=QueryFrom(i);
        if(QueryTo(i)==QueryFrom(i))
        {
            cout<<"0"<<endl;
        }
        else if(a1==QueryTo(i) || a2==QueryTo(i))
        {
            cout<<"1"<<endl;
        }
        else
        {
            while(a1!=QueryTo(i) && a2!=QueryTo(i))
            {
                x++;
                if(FirstNeighbor(a1)==tmp1)
                {
                    tmp1=a1;
                    a1=SecondNeighbor(a1);
                }
                else
                {
                    tmp1=a1;
                    a1=FirstNeighbor(a1);
                }
                if(FirstNeighbor(a2)==tmp2)
                {
                    tmp2=a2;
                    a2=SecondNeighbor(a2);
                }
                else
                {
                    tmp2=a2;
                    a2=FirstNeighbor(a2);
                }
            }
            cout<<x<<endl;
        }
    }
    }
    return 0;
}