#include "Azer.h"
#include<bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
#define eb emplace_back
#define sz(x) (int)x.size()
namespace {
vector<pii> adj[2005];
priority_queue<pii,vector<pii>,greater<pii>> pq;
int d[2005],d0[2005],n,m0,cnt,k0,v0,w0;
vector<int> tmp;
void send(bool x){ return SendA(x); }
void send(int x,int m){ while(m--) send(x&1), x>>=1; }
void push(){
tmp.clear();
for(int i=0;i<n;++i) if(d[i]!=d0[i]) tmp.eb(i), d0[i]=d[i];
if(tmp.empty()) return;
send(sz(tmp),11);
for(auto &i:tmp) send(i,11), send(d[i],20);
}
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(1e6));
fill(d0,d0+N,int(1e6));
pq.emplace(d[0]=0,0);
dijk();
push();
}
void ReceiveA(bool x) {
if(cnt<11) m0 |= x<<cnt;
else if(cnt<22) m0 |= x<<cnt-11;
else m0 |= x<<cnt-22;
++cnt;
if(cnt==11) k0=m0, m0=0;
else if(cnt==22) v0=m0, m0=0;
else if(cnt==42){
w0=m0, m0=cnt=0;
pq.emplace(d[v0]=d0[v0]=w0, v0);
if(k0) return void(cnt=11);
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
#define sz(x) (int)x.size()
namespace {
vector<pii> adj[2005];
priority_queue<pii,vector<pii>,greater<pii>> pq;
int d[2005],d0[2005],n,m0,cnt,k0,v0,w0;
vector<int> tmp;
void send(bool x){ return SendB(x); }
void send(int x,int m){ while(m--) send(x&1), x>>=1; }
void push(){
tmp.clear();
for(int i=0;i<n;++i) if(d[i]!=d0[i]) tmp.eb(i), d0[i]=d[i];
if(tmp.empty()) return;
send(sz(tmp),11);
for(auto &i:tmp) send(i,11), send(d[i],20);
}
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(1e6));
fill(d0,d0+N,int(1e6));
}
void ReceiveB(bool x) {
if(cnt<11) m0 |= x<<cnt;
else if(cnt<22) m0 |= x<<cnt-11;
else m0 |= x<<cnt-22;
++cnt;
if(cnt==11) k0=m0, m0=0;
else if(cnt==22) v0=m0, m0=0;
else if(cnt==42){
w0=m0, m0=cnt=0;
pq.emplace(d[v0]=d0[v0]=w0, v0);
if(k0) return void(cnt=11);
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... |