This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include "Azer.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'
int nA , mA , dstA[2000];
vector<arr(2)> gA[2000];
set<arr(2)> qA;
int lstA = 0;
int rcvA[3] , xxA[2];
vector<int> AA;
int cnt = 0;
void sendInfA(int x , int len){
x = min(x , 501);
for(int bit = len - 1 ; bit >= 0 ; bit--){
while(++cnt > 58000);
bool d = ((x >> bit) & 1);
SendA(d);
}
}
vector<int> Answer(){
return AA;
}
void addVtxA(int v , int x){
while(cnt > 58000);
qA.erase({dstA[v] , v});
dstA[v] = x , lstA = x;
for(auto &e : gA[v]){
if(dstA[e[0]] > dstA[v] + e[1]){
qA.erase({dstA[e[0]] , e[0]});
dstA[e[0]] = dstA[v] + e[1];
qA.insert({dstA[e[0]] , e[0]});
}
}
if(qA.empty()){
for(int i = 0 ; i < nA ; i++) AA.pb(dstA[i]);
return;
}
auto itr = qA.bg();
rcvA[0] = 9 , rcvA[1] = 0 , rcvA[2] = 0;
xxA[0] = (*itr)[1] , xxA[1] = (*itr)[0] - lstA;
sendInfA((*itr)[0] - lstA , 9);
}
void gotLenA(int len){
if(xxA[1] <= len){
sendInfA(xxA[0] , 11);
addVtxA(xxA[0] , xxA[1] + lstA);
}else{
xxA[1] = len , rcvA[0] = 11 , rcvA[1] = 0 , rcvA[2] = 1;
}
}
void ReceiveA(bool x){
int vl = int(x);
while(++cnt > 58000);
rcvA[1] += (vl << (rcvA[0] - 1));
if(--rcvA[0] == 0){
if(rcvA[2] == 0) gotLenA(rcvA[1]);
else{
if(rcvA[1] >= nA) exit(0);
addVtxA(rcvA[1] , xxA[1] + lstA);
}
}
}
void InitA(int N , int A , vector<int> U , vector<int> V , vector<int> C){
nA = N , mA = A;
fill(&dstA[0] , &dstA[nA] , int(1e9));
for(int v = 0 ; v < nA ; v++) qA.insert({dstA[v] , v});
for(int i = 0 ; i < mA ; i++) gA[U[i]].pb({V[i] , C[i]}) , gA[V[i]].pb({U[i] , C[i]});
addVtxA(0 , 0);
}
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include "Baijan.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'
int nB , mB , dstB[2000];
vector<arr(2)> gB[2000];
set<arr(2)> qB;
int lstB = 0;
int rcvB[3] , xxB[2];
void sendInfB(int x , int len){
x = min(x , 501);
while(len == 11 and x > nB);
for(int bit = len - 1 ; bit >= 0 ; bit--){
bool d = ((x >> bit) & 1);
SendB(d);
}
}
void addVtxB(int v , int x){
v = min(nB , v);
qB.erase({dstB[v] , v});
dstB[v] = x , lstB = x;
for(auto &e : gB[v]){
if(dstB[e[0]] > dstB[v] + e[1]){
qB.erase({dstB[e[0]] , e[0]});
dstB[e[0]] = dstB[v] + e[1];
qB.insert({dstB[e[0]] , e[0]});
}
}
auto itr = qB.bg();
rcvB[0] = 9 , rcvB[1] = 0 , rcvB[2] = 0;
xxB[0] = (*itr)[1] , xxB[1] = (*itr)[0] - lstB;
}
void gotLenB(int len){
if(xxB[1] <= len){
sendInfB(xxB[1] , 9);
sendInfB(xxB[1] , 11);
addVtxB(xxB[0] , xxB[1] + lstB);
}else{
int d = xxB[1];
rcvB[0] = 11 , rcvB[1] = 0 , rcvB[2] = 1 , xxB[1] = len;
sendInfB(d , 9);
}
}
void ReceiveB(bool x){
int vl = int(x);
rcvB[1] += (vl << (rcvB[0] - 1));
if(--rcvB[0] == 0){
if(rcvB[2] == 0) gotLenB(rcvB[1]);
else addVtxB(rcvB[1] , xxB[1] + lstB);
}
}
void InitB(int N , int B , vector<int> S , vector<int> T , vector<int> D){
nB = N , mB = B;
fill(&dstB[0] , &dstB[nB] , int(1e9));
for(int v = 0 ; v < nB ; v++) qB.insert({dstB[v] , v});
for(int i = 0 ; i < mB ; i++) gB[T[i]].pb({S[i] , D[i]}) , gB[S[i]].pb({T[i] , D[i]});
addVtxB(0 , 0);
}
Compilation message (stderr)
Azer.cpp: In function 'void ReceiveA(bool)':
Azer.cpp:67:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
67 | while(++cnt > 58000);
| ^~~~~
Azer.cpp:68:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
68 | rcvA[1] += (vl << (rcvA[0] - 1));
| ^~~~
Baijan.cpp: In function 'void sendInfB(int, int)':
Baijan.cpp:26:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
26 | while(len == 11 and x > nB);
| ^~~~~
Baijan.cpp:27:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
27 | for(int bit = len - 1 ; bit >= 0 ; bit--){
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |