#include <iostream>
#include <vector>
#include "message.h"
#include "kollib.h"
using namespace std;
vector<int> wiadomosci[101];
int main()
{
ios_base::sync_with_stdio(0);
for(int nr=MyNodeId(); nr<NumberOfQueries(); nr+=NumberOfNodes())
{
int pocz=QueryFrom(nr+1), koniec=QueryTo(nr+1);
if(pocz==koniec)
{
if(MyNodeId()!=0)
PutInt(0, 0);
else
wiadomosci[0].push_back(0);
continue;
}
int a, b;
a=FirstNeighbor(pocz);
b=pocz;
int licznik=1;
int tmp;
while(a!=koniec)
{
tmp=FirstNeighbor(a);
if(tmp==b) tmp=SecondNeighbor(a);
b=a;
a=tmp;
licznik++;
}
if(MyNodeId()!=0)
PutInt(0, licznik);
else
wiadomosci[0].push_back(licznik);
}
if(MyNodeId()!=0)
{
Send(0);
}
else
{
for(int n=1; n<NumberOfNodes(); n++)
{
Receive(n);
for(int nr=n; nr<NumberOfQueries(); nr+=NumberOfNodes())
{
wiadomosci[n].push_back(GetInt(n));
}
}
for(int n=0; n<wiadomosci[0].size(); n++)
{
for(int nr=0; nr<NumberOfNodes(); nr++)
{
if(wiadomosci[nr].size()>n)
cout<<min(wiadomosci[nr][n], NumberOfStudents()-wiadomosci[nr][n])<<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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include <iostream> #include <vector> #include "message.h" #include "kollib.h" using namespace std; vector<int> wiadomosci[101]; int main() { ios_base::sync_with_stdio(0); for(int nr=MyNodeId(); nr<NumberOfQueries(); nr+=NumberOfNodes()) { int pocz=QueryFrom(nr+1), koniec=QueryTo(nr+1); if(pocz==koniec) { if(MyNodeId()!=0) PutInt(0, 0); else wiadomosci[0].push_back(0); continue; } int a, b; a=FirstNeighbor(pocz); b=pocz; int licznik=1; int tmp; while(a!=koniec) { tmp=FirstNeighbor(a); if(tmp==b) tmp=SecondNeighbor(a); b=a; a=tmp; licznik++; } if(MyNodeId()!=0) PutInt(0, licznik); else wiadomosci[0].push_back(licznik); } if(MyNodeId()!=0) { Send(0); } else { for(int n=1; n<NumberOfNodes(); n++) { Receive(n); for(int nr=n; nr<NumberOfQueries(); nr+=NumberOfNodes()) { wiadomosci[n].push_back(GetInt(n)); } } for(int n=0; n<wiadomosci[0].size(); n++) { for(int nr=0; nr<NumberOfNodes(); nr++) { if(wiadomosci[nr].size()>n) cout<<min(wiadomosci[nr][n], NumberOfStudents()-wiadomosci[nr][n])<<endl; } } } } |
English