#include <cstdio>
#include "kollib.h"
#include "message.h"
using namespace std;
int a,b,c,la,lb,wyn,skad,pozycja, tab[222],ile;
bool notfound;
int min(int a, int b)
{
if(a<b)
return a;
else
return b;
}
/*
int idz(int skad, int dokad, int dlugosc)
{
while(notfound)
{
if(dokad==b)
{
wyn=dlugosc;
notfound=false;
}
if(FirstNeighbour(dokad)!=skad)
{
idz(dokad, FirstNeighbour(dokad), dlugosc+1)
}
if(SecondNeighbour(dokad)!=skad)
{
idz(dokad, SecondNeighbour(dokad), dlugosc+1)
}
}
}*/
int main()
{
for(int i=MyNodeId()+1; i<=NumberOfQueries(); i+=NumberOfNodes())
{
//notfound=true;
a=QueryFrom(i);
b=QueryTo(i);
if(a==b)
{
wyn=0;
}
//idz(a, FirstNeighbour(a), 1);
//
else
{
wyn=0;
pozycja=a;
skad=pozycja;
while(pozycja!=b)
{
c=pozycja;
wyn++;
if(skad!=FirstNeighbor(pozycja))
pozycja=FirstNeighbor(pozycja);
else
pozycja=SecondNeighbor(pozycja);
skad=c;
}
wyn=min(wyn,(NumberOfStudents()-wyn));
}
PutInt(0,wyn);
//Send(0);
}
PutInt(0,1000000009);
Send(0);
if(MyNodeId()==0)
{
for(int i=0; i<NumberOfNodes(); i++)
{
Receive(i);
ile=0;
a=GetInt(i);
while(a!=1000000009)
{
tab[i+ile*NumberOfNodes()]=a;
ile++;
//printf("%d\n", a);
a=GetInt(i);
}
}
for(int i=0; i<NumberOfQueries(); i++)
{
printf("%d\n", tab[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 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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | #include <cstdio> #include "kollib.h" #include "message.h" using namespace std; int a,b,c,la,lb,wyn,skad,pozycja, tab[222],ile; bool notfound; int min(int a, int b) { if(a<b) return a; else return b; } /* int idz(int skad, int dokad, int dlugosc) { while(notfound) { if(dokad==b) { wyn=dlugosc; notfound=false; } if(FirstNeighbour(dokad)!=skad) { idz(dokad, FirstNeighbour(dokad), dlugosc+1) } if(SecondNeighbour(dokad)!=skad) { idz(dokad, SecondNeighbour(dokad), dlugosc+1) } } }*/ int main() { for(int i=MyNodeId()+1; i<=NumberOfQueries(); i+=NumberOfNodes()) { //notfound=true; a=QueryFrom(i); b=QueryTo(i); if(a==b) { wyn=0; } //idz(a, FirstNeighbour(a), 1); // else { wyn=0; pozycja=a; skad=pozycja; while(pozycja!=b) { c=pozycja; wyn++; if(skad!=FirstNeighbor(pozycja)) pozycja=FirstNeighbor(pozycja); else pozycja=SecondNeighbor(pozycja); skad=c; } wyn=min(wyn,(NumberOfStudents()-wyn)); } PutInt(0,wyn); //Send(0); } PutInt(0,1000000009); Send(0); if(MyNodeId()==0) { for(int i=0; i<NumberOfNodes(); i++) { Receive(i); ile=0; a=GetInt(i); while(a!=1000000009) { tab[i+ile*NumberOfNodes()]=a; ile++; //printf("%d\n", a); a=GetInt(i); } } for(int i=0; i<NumberOfQueries(); i++) { printf("%d\n", tab[i]); } } // return 0; } |
English