#include "message.h"
#include "kollib.h"
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#define MAX_N 1000000001
#define MAX_M 221
#define INF 9223372036854775807
#define ll long long
using namespace std;
ll n, zapytan, odkad, dokad;
ll wynik[MAX_M];
int main()
{
ios_base::sync_with_stdio(0);
n=NumberOfStudents();
zapytan=NumberOfQueries();
for(ll i=1+MyNodeId(); i<=zapytan; i+=NumberOfNodes())
{
odkad=QueryFrom(i);
dokad=QueryTo(i);
ll licznik=1;
ll jestem=odkad;
ll poprzedni=-1;
while(jestem!=dokad)
{
ll lewy=FirstNeighbor(jestem);
ll prawy=SecondNeighbor(jestem);
if(lewy==poprzedni)
{
poprzedni=jestem;
jestem=prawy;
}
else
{
poprzedni=jestem;
jestem=lewy;
}
licznik++;
}
ll odleglosc=min(licznik-1, n-licznik+1);
if(MyNodeId()>0)
{
PutLL(0, odleglosc);
Send(0);
//wynik[i]=min(licznik+1, n-licznik+1);
}
else wynik[i]=odleglosc;
}
if(MyNodeId() == 0)
{
for(ll i=1; i<NumberOfNodes(); ++i)
{
for(ll j=1+i; j<=zapytan; j+=NumberOfNodes())
{
int instancja = Receive(i);
ll x = GetLL(i);
wynik[j]=x;
}
}
}
if(MyNodeId() == 0)
{
for(ll i=1; i<=zapytan; ++i) cout << wynik[i] << endl;
}
return 0;
}
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 | #include "message.h" #include "kollib.h" #include<iostream> #include<algorithm> #include<set> #include<vector> #define MAX_N 1000000001 #define MAX_M 221 #define INF 9223372036854775807 #define ll long long using namespace std; ll n, zapytan, odkad, dokad; ll wynik[MAX_M]; int main() { ios_base::sync_with_stdio(0); n=NumberOfStudents(); zapytan=NumberOfQueries(); for(ll i=1+MyNodeId(); i<=zapytan; i+=NumberOfNodes()) { odkad=QueryFrom(i); dokad=QueryTo(i); ll licznik=1; ll jestem=odkad; ll poprzedni=-1; while(jestem!=dokad) { ll lewy=FirstNeighbor(jestem); ll prawy=SecondNeighbor(jestem); if(lewy==poprzedni) { poprzedni=jestem; jestem=prawy; } else { poprzedni=jestem; jestem=lewy; } licznik++; } ll odleglosc=min(licznik-1, n-licznik+1); if(MyNodeId()>0) { PutLL(0, odleglosc); Send(0); //wynik[i]=min(licznik+1, n-licznik+1); } else wynik[i]=odleglosc; } if(MyNodeId() == 0) { for(ll i=1; i<NumberOfNodes(); ++i) { for(ll j=1+i; j<=zapytan; j+=NumberOfNodes()) { int instancja = Receive(i); ll x = GetLL(i); wynik[j]=x; } } } if(MyNodeId() == 0) { for(ll i=1; i<=zapytan; ++i) cout << wynik[i] << endl; } return 0; } |
English