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 "Azer.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define REP(i,j,k) for(int i=(j);i<(k);++i)
#define RREP(i,j,k) for(int i=int(j)-1;i>=(k);--i)
#define ALL(a) a.begin(),a.end()
#define pb push_back
#define f first
#define s second
#define de(...) cerr<<__VA_ARGS__
#define ar(a,s,t) {REP(__i,s,t)de(a[__i]<<' ');de(endl);}
namespace{
const int maxn=2009,inf=1e9;
int n,ls=0,t=0,fin=0,r,tmp,d[maxn];
bitset<maxn>c;
vector<pii>g[maxn];
priority_queue<pii,vector<pii>,greater<pii>>pq;
void send(int x,int l){RREP(i,l,0)SendA((x>>i)&1);}
void rlx(int u,int x){
d[u]=x;
c[u]=1;
++fin;
ls=d[u];
REP(i,0,g[u].size()){
pii&ee=g[u][i];
if(d[u]+ee.s>d[ee.f]){
d[ee.f]=d[u]+ee.s;
pq.push({d[ee.f],ee.f});
}
}
}
void proc(){
if(t==0||t==21){
while(pq.size()&&c[pq.top().s])pq.pop();
send(pq.size()?pq.top().f-ls:511,9);
t=1;
}else if(t==9){
r+=ls;
if(pq.empty()||r<pq.top().f)tmp=r;
else{
pii tt=pq.top();pq.pop();
send(tt.s,11);
t+=11;
rlx(tt.s,tt.f);
}
}else rlx(r,tmp);
}
}
void InitA(int _n,int a,vector<int>u,vector<int>v,vector<int>c) {
n=_n;
REP(i,0,a)g[u[i]].pb({v[i],c[i]}),g[v[i]].pb({u[i],c[i]});
fill(d+1,d+n,inf);
pq.push({d[0],0});
proc();
}
void ReceiveA(bool x){
if(t==1||t==10)r=0;
(r<<=1)|=x;
if(t==9||t==20)proc();
++t;
if(t==21&&fin<n)proc();
}
vector<int>Answer(){
vector<int>ret,tt;
REP(i,0,n)ret.pb(d[i]);
return tt;
}
#include "Baijan.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define REP(i,j,k) for(int i=(j);i<(k);++i)
#define RREP(i,j,k) for(int i=int(j)-1;i>=(k);--i)
#define ALL(a) a.begin(),a.end()
#define pb push_back
#define f first
#define s second
#define de(...) cerr<<__VA_ARGS__
#define ar(a,s,t) {REP(__i,s,t)de(a[__i]<<' ');de(endl);}
namespace{
const int maxn=2009,inf=1e9;
int n,ls=0,t=0,fin=0,r,tmp,d[maxn];
bitset<maxn>c;
vector<pii>g[maxn];
priority_queue<pii,vector<pii>,greater<pii>>pq;
void send(int x,int l){RREP(i,l,0)SendB((x>>i)&1);}
void rlx(int u,int x){
d[u]=x;
c[u]=1;
++fin;
ls=d[u];
REP(i,0,g[u].size()){
pii&ee=g[u][i];
if(d[u]+ee.s>d[ee.f]){
d[ee.f]=d[u]+ee.s;
pq.push({d[ee.f],ee.f});
}
}
}
void proc(){
if(t==0||t==21){
while(pq.size()&&c[pq.top().s])pq.pop();
send(pq.size()?pq.top().f-ls:511,9);
t=1;
}else if(t==9){
r+=ls;
if(pq.empty()||r<pq.top().f)tmp=r;
else{
pii tt=pq.top();pq.pop();
send(tt.s,11);
t+=11;
rlx(tt.s,tt.f);
}
}else rlx(r,tmp);
}
}
void InitB(int _n,int a,vector<int>u,vector<int>v,vector<int>c) {
n=_n;
REP(i,0,a)g[u[i]].pb({v[i],c[i]}),g[v[i]].pb({u[i],c[i]});
fill(d+1,d+n,inf);
pq.push({d[0],0});
proc();
}
void ReceiveB(bool x){
if(t==1||t==10)r=0;
(r<<=1)|=x;
if(t==9||t==20)proc();
++t;
if(t==21&&fin<n)proc();
}
Compilation message (stderr)
Azer.cpp: In function 'void {anonymous}::rlx(int, int)':
Azer.cpp:5:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define REP(i,j,k) for(int i=(j);i<(k);++i)
^
Azer.cpp:27:3: note: in expansion of macro 'REP'
REP(i,0,g[u].size()){
^~~
Baijan.cpp: In function 'void {anonymous}::rlx(int, int)':
Baijan.cpp:5:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define REP(i,j,k) for(int i=(j);i<(k);++i)
^
Baijan.cpp:27:3: note: in expansion of macro 'REP'
REP(i,0,g[u].size()){
^~~
# | 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... |