#include "message.h" #include "kollib.h" #include <iostream> using namespace std; int main() { int n, m, non, me; int wynik; int i; int from, to; int prev1, prev2, last1, last2, next1, next2; n = NumberOfStudents(); m = NumberOfQueries(); non = NumberOfNodes(); me = MyNodeId(); for (i = 0; i < m; i++) if (i % non == me) { from = QueryFrom(i + 1); to = QueryTo(i + 1); wynik = 0; if (from != to) { wynik = 1; last1 = FirstNeighbor(from); last2 = SecondNeighbor(from); prev1 = from; prev2 = from; while (last1 != to && last2 != to) { wynik++; next1 = FirstNeighbor(last1); if (next1 == prev1) next1 = SecondNeighbor(last1); next2 = FirstNeighbor(last2); if (next2 == prev2) next2 = SecondNeighbor(last2); prev1 = last1; prev2 = last2; last1 = next1; last2 = next2; } } PutInt(0, wynik); Send(0); } if (me == 0) for (i = 0; i < m; i++) { Receive(i % non); cout << GetInt(i % non) << 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 | #include "message.h" #include "kollib.h" #include <iostream> using namespace std; int main() { int n, m, non, me; int wynik; int i; int from, to; int prev1, prev2, last1, last2, next1, next2; n = NumberOfStudents(); m = NumberOfQueries(); non = NumberOfNodes(); me = MyNodeId(); for (i = 0; i < m; i++) if (i % non == me) { from = QueryFrom(i + 1); to = QueryTo(i + 1); wynik = 0; if (from != to) { wynik = 1; last1 = FirstNeighbor(from); last2 = SecondNeighbor(from); prev1 = from; prev2 = from; while (last1 != to && last2 != to) { wynik++; next1 = FirstNeighbor(last1); if (next1 == prev1) next1 = SecondNeighbor(last1); next2 = FirstNeighbor(last2); if (next2 == prev2) next2 = SecondNeighbor(last2); prev1 = last1; prev2 = last2; last1 = next1; last2 = next2; } } PutInt(0, wynik); Send(0); } if (me == 0) for (i = 0; i < m; i++) { Receive(i % non); cout << GetInt(i % non) << endl; } return(0); } |