#include <cstdio>
#include <vector>
#include <kollib.h>
#include <message.h>
using namespace std;
int tab[10000005];
int main(){
int ile=NumberOfStudents();
int ileP=NumberOfQueries();
int idInstancji=MyNodeId();
if(idInstancji!=0) return 0;
int ost=1, post=0, w;
for(int i=1; i<ile; i++){
if(FirstNeighbor(ost)==post){
post=ost;
ost=SecondNeighbor(ost);
tab[ost]=i;
}
else{
post=ost;
ost=FirstNeighbor(ost);
tab[ost]=i;
}
}
for(int i=0; i<ileP; i++){
w=max(tab[QueryFrom(i)],tab[QueryTo(i)])-min(tab[QueryFrom(i)],tab[QueryTo(i)]);
if(w>int(ile/2)) w=ile-w;
printf("%d\n",w);
}
}
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 | #include <cstdio> #include <vector> #include <kollib.h> #include <message.h> using namespace std; int tab[10000005]; int main(){ int ile=NumberOfStudents(); int ileP=NumberOfQueries(); int idInstancji=MyNodeId(); if(idInstancji!=0) return 0; int ost=1, post=0, w; for(int i=1; i<ile; i++){ if(FirstNeighbor(ost)==post){ post=ost; ost=SecondNeighbor(ost); tab[ost]=i; } else{ post=ost; ost=FirstNeighbor(ost); tab[ost]=i; } } for(int i=0; i<ileP; i++){ w=max(tab[QueryFrom(i)],tab[QueryTo(i)])-min(tab[QueryFrom(i)],tab[QueryTo(i)]); if(w>int(ile/2)) w=ile-w; printf("%d\n",w); } } |
English