#include "kollib.h" #include "message.h" #include<cstdio> int poprz,akt,koniec,ilosc,num,ktora; int main(){ if(MyNodeId() > 0){ num = NumberOfStudents(); for(int i = MyNodeId(); i <= NumberOfQueries(); i+= (NumberOfNodes()-1)){ ilosc = 1; poprz = QueryFrom(i); koniec = QueryTo(i); if(poprz == koniec){ ilosc = 0; PutInt(0,ilosc); Send(0); } else{ akt = FirstNeighbor(poprz); while(akt != koniec){ if(FirstNeighbor(akt) == poprz){ poprz = akt; akt = SecondNeighbor(akt); } else{ poprz = akt; akt = FirstNeighbor(akt); } ilosc++; } if(ilosc > (num/2)){ ilosc = (num - ilosc); } PutInt(0,ilosc); Send(0); } } } else{ for(int ins = 0;ins < NumberOfQueries();ins++){ ktora = ( (ins % (NumberOfNodes()-1)) + 1); Receive(ktora); printf("%d\n",GetInt(ktora)); } } 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 | #include "kollib.h" #include "message.h" #include<cstdio> int poprz,akt,koniec,ilosc,num,ktora; int main(){ if(MyNodeId() > 0){ num = NumberOfStudents(); for(int i = MyNodeId(); i <= NumberOfQueries(); i+= (NumberOfNodes()-1)){ ilosc = 1; poprz = QueryFrom(i); koniec = QueryTo(i); if(poprz == koniec){ ilosc = 0; PutInt(0,ilosc); Send(0); } else{ akt = FirstNeighbor(poprz); while(akt != koniec){ if(FirstNeighbor(akt) == poprz){ poprz = akt; akt = SecondNeighbor(akt); } else{ poprz = akt; akt = FirstNeighbor(akt); } ilosc++; } if(ilosc > (num/2)){ ilosc = (num - ilosc); } PutInt(0,ilosc); Send(0); } } } else{ for(int ins = 0;ins < NumberOfQueries();ins++){ ktora = ( (ins % (NumberOfNodes()-1)) + 1); Receive(ktora); printf("%d\n",GetInt(ktora)); } } return 0; } |