# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
708227 | alvingogo | Two Transportations (JOI19_transportations) | C++14 | 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"
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
namespace{
vector<int> dis;
int n;
int m;
vector<vector<pair<int,int> > > gg;
int nw,f=-1,r=-1,c=-1;
int cnt=0;
int flag=-1;
int z=0;
}
void InitA(int N, int A, std::vector<int> U, std::vector<int> V, std::vector<int> C){
n=N;
m=A;
gg.resize(n);
for(int i=0;i<m;i++){
gg[U[i]].push_back({V[i],C[i]});
gg[V[i]].push_back({V[i],C[i]});
}
}
void ReceiveA(bool x){
if(flag==-1){
flag=x;
return;
}
nw=nw*2+x;
cnt++;
if(flag==0){
if(cnt==20){
dis[z]=nw;
nw=0;
cnt=0;
z++;
}
}
else{
if(cnt==11){
if(f==-1){
f=nw;
}
else if(r==-1){
r=nw;
}
else if(c==-1){
c=nw;
gg[f].push_back({r,c});
gg[r].push_back({f,c});
}
else{
assert(0);
}
cnt=0;
nw=0;
}
}
}
std::vector<int> Answer(){
if(flag){
p_q<pair<int,int> > pq;
pq.push({0,0});
while(pq.size()){
auto h=pq.top();
pq.pop();
h.fs*=-1;
if(h.fs!=dis[h.sc]){
continue;
}
for(auto y:gg[h.sc]){
if(dis[y.fs]>h.fs+y.sc){
dis[y.fs]=h.fs+y.sc;
pq.push({-dis[y.fs],y.fs});
}
}
}
}
return dis;
}
#include <bits/stdc++.h>
#include "Baijan.h"
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
void send(int a,int i){
i--;
for(;i>=0;i--){
sendB((a>>i)&1);
}
}
void InitB(int N, int B, std::vector<int> S, std::vector<int> T, std::vector<int> D){
if(B<=1000){
sendB(1);
for(int i=0;i<B;i++){
send(S[i],11);
send(T[i],11);
send(D[i],11);
}
}
else{
sendB(0);
vector<int> dis(N);
vector<vector<pair<int,int> > gg(N);
for(int i=0;i<B;i++){
gg[S[i]].push_back({T[i],D[i]});
gg[T[i]].push_back({T[i],D[i]});
}
p_q<pair<int,int> > pq;
pq.push({0,0});
while(pq.size()){
auto h=pq.top();
pq.pop();
h.fs*=-1;
if(h.fs!=dis[h.sc]){
continue;
}
for(auto y:gg[h.sc]){
if(dis[y.fs]>h.fs+y.sc){
dis[y.fs]=h.fs+y.sc;
pq.push({-dis[y.fs],y.fs});
}
}
}
for(int i=0;i<n;i++){
send(dis[i],20);
}
}
}