#include <iostream> #include <algorithm> #include <stdio.h> #include <string> #include <vector> #include <map> #include <stack> #include <set> #include <math.h> #include <queue> #include "message.h" #include "kollib.h" using namespace std; int main() { cin.tie(NULL); ios::sync_with_stdio(false); int N = NumberOfStudents(); int numberOfNodes = NumberOfNodes(); int myId = MyNodeId(); int numberOfQueries = NumberOfQueries(); for(int questionId = MyNodeId() + 1; questionId <= numberOfQueries; questionId += numberOfNodes) { int from = QueryFrom(questionId); int to = QueryTo(questionId); int result = 0; int current = from; int lastVisited = FirstNeighbor(current); while(current != to) { int firstNeigh = FirstNeighbor(current);; int secondNeigh = SecondNeighbor(current); if(firstNeigh != lastVisited) { lastVisited = current; current = firstNeigh; } else { lastVisited = current; current = secondNeigh; } result++; } result = min(result, N - result); PutInt(0, result); } Send(0); if(myId != 0) return 0; vector<int> answers(numberOfQueries + 1); for(int nodeId = 0; nodeId < numberOfNodes; nodeId++) { Receive(nodeId); for(int questionId = nodeId + 1; questionId <= numberOfQueries; questionId += numberOfNodes) { int answer = GetInt(nodeId); answers[questionId] = answer; } } for(int questionId = 1; questionId <= numberOfQueries; questionId++) { if(questionId != 1) cout << "\n"; cout << answers[questionId]; } 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 | #include <iostream> #include <algorithm> #include <stdio.h> #include <string> #include <vector> #include <map> #include <stack> #include <set> #include <math.h> #include <queue> #include "message.h" #include "kollib.h" using namespace std; int main() { cin.tie(NULL); ios::sync_with_stdio(false); int N = NumberOfStudents(); int numberOfNodes = NumberOfNodes(); int myId = MyNodeId(); int numberOfQueries = NumberOfQueries(); for(int questionId = MyNodeId() + 1; questionId <= numberOfQueries; questionId += numberOfNodes) { int from = QueryFrom(questionId); int to = QueryTo(questionId); int result = 0; int current = from; int lastVisited = FirstNeighbor(current); while(current != to) { int firstNeigh = FirstNeighbor(current);; int secondNeigh = SecondNeighbor(current); if(firstNeigh != lastVisited) { lastVisited = current; current = firstNeigh; } else { lastVisited = current; current = secondNeigh; } result++; } result = min(result, N - result); PutInt(0, result); } Send(0); if(myId != 0) return 0; vector<int> answers(numberOfQueries + 1); for(int nodeId = 0; nodeId < numberOfNodes; nodeId++) { Receive(nodeId); for(int questionId = nodeId + 1; questionId <= numberOfQueries; questionId += numberOfNodes) { int answer = GetInt(nodeId); answers[questionId] = answer; } } for(int questionId = 1; questionId <= numberOfQueries; questionId++) { if(questionId != 1) cout << "\n"; cout << answers[questionId]; } return 0; } |