#include "kollib.h" #include "message.h" #include <cstdio> int main() { const int printer = NumberOfNodes() - 1; for (int q = MyNodeId() + 1; q <= NumberOfQueries(); q += NumberOfNodes()) { int i = 0, first = QueryFrom(q), oldFirst, second, oldSecond, qto = QueryTo(q); oldFirst = oldSecond = first; if(qto != first) { first = FirstNeighbor(oldFirst); second = SecondNeighbor(oldSecond); for(i = 1; i < NumberOfStudents(); i++) { if(first == qto || second == qto) break; int t = (oldFirst == FirstNeighbor(first)) ? SecondNeighbor(first) : FirstNeighbor(first); oldFirst = first; first = t; t = (oldSecond == FirstNeighbor(second)) ? SecondNeighbor(second) : FirstNeighbor(second); oldSecond = second; second = t; } } PutInt(printer, i); } Send(printer); if(MyNodeId() == printer) { int queries = NumberOfQueries(); int answers[202]; for(int i = 0; i < NumberOfNodes(); i++) { Receive(i); for (int q = i + 1; q <= NumberOfQueries(); q += NumberOfNodes()) { answers[q] = GetInt(i); } } for(int i = 1; i <= NumberOfQueries(); i++) { printf("%d\n", answers[i]); } } 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 | #include "kollib.h" #include "message.h" #include <cstdio> int main() { const int printer = NumberOfNodes() - 1; for (int q = MyNodeId() + 1; q <= NumberOfQueries(); q += NumberOfNodes()) { int i = 0, first = QueryFrom(q), oldFirst, second, oldSecond, qto = QueryTo(q); oldFirst = oldSecond = first; if(qto != first) { first = FirstNeighbor(oldFirst); second = SecondNeighbor(oldSecond); for(i = 1; i < NumberOfStudents(); i++) { if(first == qto || second == qto) break; int t = (oldFirst == FirstNeighbor(first)) ? SecondNeighbor(first) : FirstNeighbor(first); oldFirst = first; first = t; t = (oldSecond == FirstNeighbor(second)) ? SecondNeighbor(second) : FirstNeighbor(second); oldSecond = second; second = t; } } PutInt(printer, i); } Send(printer); if(MyNodeId() == printer) { int queries = NumberOfQueries(); int answers[202]; for(int i = 0; i < NumberOfNodes(); i++) { Receive(i); for (int q = i + 1; q <= NumberOfQueries(); q += NumberOfNodes()) { answers[q] = GetInt(i); } } for(int i = 1; i <= NumberOfQueries(); i++) { printf("%d\n", answers[i]); } } return 0; } |