#include <iostream>
#include "kollib.h"
#include "message.h"
using namespace std;
main()
{
int i = 0;
for(int j = 0; j < NumberOfQueries(); j++) {
//if(MyNodeId() == j ) {
int from = QueryFrom(j+1);
int to = QueryTo(j+1);
int from1= QueryFrom(j+1);
int x = FirstNeighbor(from), y = SecondNeighbor(from);
//cout << QueryTo(j+1) << endl;
while(from != to && from1 != to) {
i++;
if(FirstNeighbor(x) != from) {
from = x;
x = FirstNeighbor(x);
//cout << "from " << from << endl;
}else{
from = x;
x = SecondNeighbor(x);
//cout << "from " << from << endl;
}
if(FirstNeighbor(y) != from1) {
from1 = y;
y = FirstNeighbor(y);
//cout << "from1 " << from1 << endl;
}else{
from1 = y;
y = SecondNeighbor(y);
//cout << "from1 " << from1 << endl;
}
}}
if(MyNodeId() == 1)
cout << i << endl;
}//}
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 | #include <iostream> #include "kollib.h" #include "message.h" using namespace std; main() { int i = 0; for(int j = 0; j < NumberOfQueries(); j++) { //if(MyNodeId() == j ) { int from = QueryFrom(j+1); int to = QueryTo(j+1); int from1= QueryFrom(j+1); int x = FirstNeighbor(from), y = SecondNeighbor(from); //cout << QueryTo(j+1) << endl; while(from != to && from1 != to) { i++; if(FirstNeighbor(x) != from) { from = x; x = FirstNeighbor(x); //cout << "from " << from << endl; }else{ from = x; x = SecondNeighbor(x); //cout << "from " << from << endl; } if(FirstNeighbor(y) != from1) { from1 = y; y = FirstNeighbor(y); //cout << "from1 " << from1 << endl; }else{ from1 = y; y = SecondNeighbor(y); //cout << "from1 " << from1 << endl; } }} if(MyNodeId() == 1) cout << i << endl; }//} |
English