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
#include <iostream>
#include "message.h"
#include "kollib.h"
using namespace std;
int main()
{
int in,out,n1,n2,licznik,n11,n21;
for (int imain=1;imain<=NumberOfQueries();imain++)
{
in=QueryFrom(imain);
out=QueryTo(imain);
n1=FirstNeighbor(in);
n11=n21=in;
n2=SecondNeighbor(in);
licznik=1;
//cout<<in<<" "<<out<<" "<<n1<<" "<<n2<<endl;
if(in==out && MyNodeId()==0)
    cout<<0<<endl;
else
{

while( n1!=out && n2!=out)
{
    licznik++;
    if (FirstNeighbor(n1)==n11)
    {
    n11=n1;
    n1=SecondNeighbor(n1);
    }
    else
    {
    n11=n1;
    n1=FirstNeighbor(n1);
    }
    if (FirstNeighbor(n2)==n21)
    {
    n21=n2;
    n2=SecondNeighbor(n2);
    }
    else
    {
    n21=n2;
    n2=FirstNeighbor(n2);
    }

   // cout<<n1<<" "<<n2<<endl;

    //n2=SecondNeighbor(n2);
}
if (MyNodeId()==0)
cout<<licznik<<endl;;
}}
return 0;}