#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include "message.h"
#include "kollib.h"
using namespace std;
int main () {
ios_base::sync_with_stdio(0);
int m=NumberOfQueries();
unsigned n=NumberOfStudents();
int z=NumberOfNodes();
unsigned id=MyNodeId();
id++;
if(n<=1000000)
{
int AA[1000000+77];
unsigned int pp=1, xx=FirstNeighbor(1), tmp, dd=1, aa, bb;
AA[1]=0;
while(xx!=1) {
AA[xx]=dd;
dd++;
if(pp==FirstNeighbor(xx))
{
tmp=xx;
xx=SecondNeighbor(xx);
pp=tmp;
}
else
{
tmp=xx;
xx=FirstNeighbor(xx);
pp=tmp;
}
}
if(id==1)
for(int i=1; i<=m; i++)
{
aa=QueryFrom(i);
bb=QueryTo(i);
unsigned int abst=max(AA[aa], AA[bb]) - min(AA[aa], AA[bb]);
cout<<min( abst, n-abst )<<endl;
}
}
else
{
for(int i=id; i<=m ; i+=z)
{
unsigned int aa=QueryFrom(i);
unsigned int bb=QueryTo(i);
unsigned dd=1, tmp, pp;
unsigned xx=FirstNeighbor(aa);
while(xx!=bb) {
if(pp==FirstNeighbor(xx))
{
tmp=xx;
xx=SecondNeighbor(xx);
pp=tmp;
}
else
{
tmp=xx;
xx=FirstNeighbor(xx);
pp=tmp;
}
dd++;
}
long long ww=min(dd, n-dd);
PutLL(0, ww);
Send(0);
}
unsigned k;
if(id==1)
for(int i=0; i<m; i++)
{
k=i;
k%=z;
Receive(k);
cout<<GetLL(k)<<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 76 77 78 79 80 81 82 83 84 85 86 | #include<iostream> #include<vector> #include<queue> #include<algorithm> #include "message.h" #include "kollib.h" using namespace std; int main () { ios_base::sync_with_stdio(0); int m=NumberOfQueries(); unsigned n=NumberOfStudents(); int z=NumberOfNodes(); unsigned id=MyNodeId(); id++; if(n<=1000000) { int AA[1000000+77]; unsigned int pp=1, xx=FirstNeighbor(1), tmp, dd=1, aa, bb; AA[1]=0; while(xx!=1) { AA[xx]=dd; dd++; if(pp==FirstNeighbor(xx)) { tmp=xx; xx=SecondNeighbor(xx); pp=tmp; } else { tmp=xx; xx=FirstNeighbor(xx); pp=tmp; } } if(id==1) for(int i=1; i<=m; i++) { aa=QueryFrom(i); bb=QueryTo(i); unsigned int abst=max(AA[aa], AA[bb]) - min(AA[aa], AA[bb]); cout<<min( abst, n-abst )<<endl; } } else { for(int i=id; i<=m ; i+=z) { unsigned int aa=QueryFrom(i); unsigned int bb=QueryTo(i); unsigned dd=1, tmp, pp; unsigned xx=FirstNeighbor(aa); while(xx!=bb) { if(pp==FirstNeighbor(xx)) { tmp=xx; xx=SecondNeighbor(xx); pp=tmp; } else { tmp=xx; xx=FirstNeighbor(xx); pp=tmp; } dd++; } long long ww=min(dd, n-dd); PutLL(0, ww); Send(0); } unsigned k; if(id==1) for(int i=0; i<m; i++) { k=i; k%=z; Receive(k); cout<<GetLL(k)<<endl; } } return 0; } |
English