# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
984516 | user736482 | Two Transportations (JOI19_transportations) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include<Azer.h>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>pq;
int stan=9,akbit,czyt,czyt2,liczbaodwiedzonych=1,n,last;
int odwiedzone[2137 + 1];
vector<pair<int, int>> sasiedzi[2000];
vector<int>answer;
void sendInt(int a,int rozmiar){
vector<bool>v;
for(int i=0;i<rozmiar;i++){
v.push_back(a%2);
a/=2;
}
for(int i=rozmiar-1;i>=0;i++){
SendA(v[i]);
}
}
void InitA(int N, int A, vector<int>U, vector<int>V, vector<int>C) {
odwiedzone[0] = 1;
n = N;
for (int i = 1; i < N; i++)
answer.push_back(9999999);
for (int i = 0; i < A; i++) {
sasiedzi[U[i]].push_back({ C[i],V[i] });
sasiedzi[V[i]].push_back({ C[i],U[i] });
}
for (int i = 0; i < (int)sasiedzi[0].size(); i++) {
pq.push(sasiedzi[0][i]);
}
sendInt(pq.top().first,9);
}
void ReceiveA(bool y){
if(stan == 9){
czyt*=2;
czyt+=y;
akbit++;
if(akbit==9){
if(liczbaodwiedzonych==n)
return;
liczbaodwiedzonych++;
while(!pq.empty() && odwiedzone[pq.top().second])
pq.pop();
if(pq.empty())
pq.push({510,2137});
if(pq.top().first-last>czyt){
odwiedzone[pq.top().second] = 1;
answer[pq.top().second] = pq.top().first.first;
for (int i = 0; i < (int)sasiedzi[pq.top().second].size(); i++) {
pq.push({ sasiedzi[pq.top().second][i].first + pq.top().first + last,sasiedzi[pq.top().second][i].second });
}
last+ = pq.top().first;
czyt=0;
sendInt(pq.top().second,11);
pq.pop();
while(!pq.empty() && odwiedzone[pq.top().second])
pq.pop();
if(pq.empty())
pq.push({510,2137});
sendInt(pq.top().first-last,9);
}
else{
stan=11;
}
akbit=0;
}
}
if(stan==11){
czyt2*=2;
czyt2+=y;
akbit++;
if(akbit==11){
akbit=0;
answer[czyt2]=czyt+last;
for (int i = 0; i < (int)sasiedzi[czyt2].size(); i++) {
pq.push({ sasiedzi[czyt2][i].first + czyt + last,sasiedzi[pq.top().second][i].second });
}
czyt=0;
czyt2=0;
while(!pq.empty() && odwiedzone[pq.top().second])
pq.pop();
if(pq.empty())
pq.push({510,2137});
sendInt(pq.top().first-last-czyt,9);
last+=czyt;
}
}
}
vector<int>Answer(){
return answer;
}
#include<bits/stdc++.h>
#include<Baijan.h>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>pq;
int stan=9,akbit,czyt,czyt2,liczbaodwiedzonych=1,n,last;
int odwiedzone[2137 + 1];
vector<pair<int, int>> sasiedzi[2000];
vector<int>answer;
void sendInt(int a,int rozmiar){
vector<bool>v;
for(int i=0;i<rozmiar;i++){
v.push_back(a%2);
a/=2;
}
for(int i=rozmiar-1;i>=0;i++){
SendB(v[i]);
}
}
void InitB(int N, int B, vector<int>U, vector<int>V, vector<int>C) {
odwiedzone[0] = 1;
n = N;
for (int i = 1; i < N; i++)
answer.push_back(9999999);
for (int i = 0; i < B; i++) {
sasiedzi[U[i]].push_back({ C[i],V[i] });
sasiedzi[V[i]].push_back({ C[i],U[i] });
}
for (int i = 0; i < (int)sasiedzi[0].size(); i++) {
pq.push(sasiedzi[0][i]);
}
sendInt(pq.top().first,9);
}
void ReceiveB(bool y){
if(stan == 9){
czyt*=2;
czyt+=y;
akbit++;
if(akbit==9){
if(liczbaodwiedzonych==n)
return;
liczbaodwiedzonych++;
while(!pq.empty() && odwiedzone[pq.top().second])
pq.pop();
if(pq.empty())
pq.push({510,2137});
if(pq.top().first-last>czyt){
odwiedzone[pq.top().second] = 1;
answer[pq.top().second] = pq.top().first.first;
for (int i = 0; i < (int)sasiedzi[pq.top().second].size(); i++) {
pq.push({ sasiedzi[pq.top().second][i].first + pq.top().first + last,sasiedzi[pq.top().second][i].second });
}
last+ = pq.top().first;
czyt=0;
sendInt(pq.top().second,11);
pq.pop();
while(!pq.empty() && odwiedzone[pq.top().second])
pq.pop();
if(pq.empty())
pq.push({510,2137});
sendInt(pq.top().first-last,9);
}
else{
stan=11;
}
akbit=0;
}
}
if(stan==11){
czyt2*=2;
czyt2+=y;
akbit++;
if(akbit==11){
akbit=0;
answer[czyt2]=czyt+last;
for (int i = 0; i < (int)sasiedzi[czyt2].size(); i++) {
pq.push({ sasiedzi[czyt2][i].first + czyt + last,sasiedzi[pq.top().second][i].second });
}
czyt=0;
czyt2=0;
while(!pq.empty() && odwiedzone[pq.top().second])
pq.pop();
if(pq.empty())
pq.push({510,2137});
sendInt(pq.top().first-last-czyt,9);
last+=czyt;
}
}
}