#include "Azer.h"
#include<bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
#define eb emplace_back
namespace {
vector<pii> adj[2005];
priority_queue<pii,vector<pii>,greater<pii>> pq;
int d[2005],d0[2005];
vector<pii> tmp;
int m0,cnt,n,w0;
void send(bool x){
return SendA(x);
}
void push(){
for(int i=0;i<n;++i) if(d[i]<d0[i]){
d0[i]=d[i];
int w=d[i], v=i;
for(int i=0;i<20;++i) send(w&1), w>>=1;
for(int i=0;i<11;++i) send(v&1), v>>=1;
}
}
void dijk(){
while(!pq.empty()){
auto [w,u] = pq.top(); pq.pop();
if(d[u]!=w) continue;
for(auto &[v,vw]:adj[u]) if(d[v]>w+vw) pq.emplace(d[v]=w+vw,v);
}
}
} // namespace
void InitA(int N, int A, std::vector<int> U, std::vector<int> V, std::vector<int> C) {
n=N;
for(int i=0;i<A;++i) adj[U[i]].eb(V[i],C[i]), adj[V[i]].eb(U[i],C[i]);
m0=cnt=0;
fill(d,d+N,int(1e9));
fill(d0,d0+N,int(1e9));
pq.emplace(d[0]=0,0);
dijk();
push();
}
void ReceiveA(bool x) {
if(cnt<20) m0 |= x<<cnt;
else m0 |= x<<cnt-20;
++cnt;
if(cnt==20) w0=m0, m0=0;
else if(cnt==31){
int w=w0, v=m0;
m0=cnt=0;
if(d[v]>w) pq.emplace(d[v]=d0[v]=w,v);
dijk();
push();
}
}
std::vector<int> Answer() {
vector<int> ans(n);
for(int i=0;i<n;++i) ans[i]=d[i];
return ans;
}
#include "Baijan.h"
#include<bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
#define eb emplace_back
namespace {
vector<pii> adj[2005];
priority_queue<pii,vector<pii>,greater<pii>> pq;
int d[2005],d0[2005];
vector<pii> tmp;
int m0,cnt,n,w0;
void send(bool x){
return SendB(x);
}
void push(){
for(int i=0;i<n;++i) if(d[i]<d0[i]){
d0[i]=d[i];
int w=d[i], v=i;
for(int i=0;i<20;++i) send(w&1), w>>=1;
for(int i=0;i<11;++i) send(v&1), v>>=1;
}
}
void dijk(){
while(!pq.empty()){
auto [w,u] = pq.top(); pq.pop();
if(d[u]!=w) continue;
for(auto &[v,vw]:adj[u]) if(d[v]>w+vw) pq.emplace(d[v]=w+vw,v);
}
}
} // namespace
void InitB(int N, int A, std::vector<int> U, std::vector<int> V, std::vector<int> C) {
n=N;
for(int i=0;i<A;++i) adj[U[i]].eb(V[i],C[i]), adj[V[i]].eb(U[i],C[i]);
m0=cnt=0;
fill(d,d+N,int(1e9));
fill(d0,d0+N,int(1e9));
pq.emplace(d[0]=0,0);
}
void ReceiveB(bool x) {
if(cnt<20) m0 |= x<<cnt;
else m0 |= x<<cnt-20;
++cnt;
if(cnt==20) w0=m0, m0=0;
else if(cnt==31){
int w=w0, v=m0;
m0=cnt=0;
if(d[v]>w) pq.emplace(d[v]=d0[v]=w,v);
dijk();
push();
}
}
# | 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... |