// i-ta instancja wysyla do (i+1)-szej jedna wiadomosc z jednym int-em
#include "message.h"
#include <assert.h>
#include<vector>
#include <cstdio>
#include<algorithm>
#include "kollib.h"
#define PB push_back
using namespace std;
//vector<int> wyn;
void rozwiaz(int a, int b)
{
//printf("SSS\n");
int ost = a;
int aktual = FirstNeighbor(a);
int dlug =1;
while (aktual != b)
{
if (FirstNeighbor(aktual)==ost)
{
ost = aktual;
aktual = SecondNeighbor(aktual);
}
else
{
ost = aktual;
aktual = FirstNeighbor(aktual);
}
dlug++;
}
//wyn.PB(
printf("%d\n", min(dlug, NumberOfStudents()-dlug));
}
int main() {
int v = 0;
int idd = MyNodeId();
// printf("%d\n", idd);
if (idd==0)
{
// printf("%d\n", idd);
int ileZ = NumberOfQueries();
int ileK = NumberOfNodes();
/*int ileNa = ileZ/ileK;
int od = idd*ileNa+min(ileZ%ileK, idd);
if (ileZ%ileK > idd)
{
ileNa++;
}
int dok = od+ileNa;*/
for (int i=1; i<=ileZ; i++)
{
int a = QueryFrom(i);
int b= QueryTo(i);
rozwiaz(a, b);
}
}
/*
if (idd > 0) {
Receive(MyNodeId() - 1);
v = GetInt(MyNodeId() - 1);
}
assert(v == MyNodeId());
printf("chce wypisywac %d %d", idd, v);
for (int i=0; i<wyn.size(); i++)
{
printf("%d\n", wyn[i]);
}
if (MyNodeId() < NumberOfNodes() - 1) {
PutInt(MyNodeId() + 1, v + 1);
Send(MyNodeId() + 1);
}*/
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 | // i-ta instancja wysyla do (i+1)-szej jedna wiadomosc z jednym int-em #include "message.h" #include <assert.h> #include<vector> #include <cstdio> #include<algorithm> #include "kollib.h" #define PB push_back using namespace std; //vector<int> wyn; void rozwiaz(int a, int b) { //printf("SSS\n"); int ost = a; int aktual = FirstNeighbor(a); int dlug =1; while (aktual != b) { if (FirstNeighbor(aktual)==ost) { ost = aktual; aktual = SecondNeighbor(aktual); } else { ost = aktual; aktual = FirstNeighbor(aktual); } dlug++; } //wyn.PB( printf("%d\n", min(dlug, NumberOfStudents()-dlug)); } int main() { int v = 0; int idd = MyNodeId(); // printf("%d\n", idd); if (idd==0) { // printf("%d\n", idd); int ileZ = NumberOfQueries(); int ileK = NumberOfNodes(); /*int ileNa = ileZ/ileK; int od = idd*ileNa+min(ileZ%ileK, idd); if (ileZ%ileK > idd) { ileNa++; } int dok = od+ileNa;*/ for (int i=1; i<=ileZ; i++) { int a = QueryFrom(i); int b= QueryTo(i); rozwiaz(a, b); } } /* if (idd > 0) { Receive(MyNodeId() - 1); v = GetInt(MyNodeId() - 1); } assert(v == MyNodeId()); printf("chce wypisywac %d %d", idd, v); for (int i=0; i<wyn.size(); i++) { printf("%d\n", wyn[i]); } if (MyNodeId() < NumberOfNodes() - 1) { PutInt(MyNodeId() + 1, v + 1); Send(MyNodeId() + 1); }*/ return 0; } |
English