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

int n;
vector<pair<int,int> > tab[1000009];
int mx;
bool be( int x )
{
    for( int i=0; i<tab[x%mx].size(); i++ )
    {
        if ( tab[x%mx][i].first== x)
        {
            return false;
        }
    }
    return true;
}
int wyn( int x)
{
    for( int i=0; i<tab[x%mx].size(); i++ )
    {
        if ( tab[x%mx][i].first==x)
        {
            return tab[x%mx][i].second;
        }
    }
    return 0;
}
int bfs( int a, int b)
{
    queue<int> Q;
    Q.push(a);
    int u;
    pair<int,int> p;
    p.first=a;
    p.second=0;
    int fn;
    tab[a%mx].push_back(p);
    while ( !Q.empty() )
    {
        u=Q.front();
        Q.pop();
        b=true;
        fn = FirstNeighbor(u);
        if ( fn==b )
        {
            return wyn( u )+1;
        }
        if ( be(fn)==true )
        {
            p.first=fn;
            p.second=wyn(u)+1;
            Q.push(p.first);
            tab[fn%mx].push_back(p);
        }
        fn = SecondNeighbor(u);
        if ( fn==b )
        {
            return wyn( u )+1;
        }
        if ( be(fn)==true )
        {
            p.first=fn;
            p.second=wyn(u)+1;
            Q.push(p.first);
            tab[fn%mx].push_back(p);
        }
    }
    return 0;
}
int q;
int odp[208];

int main()
{
    mx=1000008;
    n=NumberOfStudents();
    q=NumberOfQueries();
    int k;
    int l;
    for ( int i=0; i<q; i++ )
    {
        odp[i]=( QueryFrom(i), QueryTo(i) );
    }
    for ( int i=0; i<q; i++ )
    {
        cout << odp[i] << endl ;
    }
    return 0;
}