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>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;
namespace A
{
const ll maxn=2005, inf=1<<20;
vector <pll> A[maxn];
ll n, last, cru, crd, crv, cnt, dis[maxn], check[maxn];
void update(ll u)
{
check[u]=1, last=dis[u];
for (auto [v, w]:A[u])
dis[v]=min(dis[v], dis[u]+w);
}
void senddis()
{
ll big=-1;
for (ll i=0; i<n; i++)
if (!check[i] && (big==-1 || dis[i]<dis[big]))
big=i;
if (big==-1) return; cru=big;
ll d=min(511, dis[big]-last);
for (ll i=0; i<9; i++) SendA(d>>i&1);
// cout << "A sent distance: " << d << "\n";
}
void sendidx(ll idx) {
// cout << "A sent index: " << idx << "\n";
for (ll i=0; i<11; i++) SendA(idx>>i&1);}
void init(ll N)
{
n=N, last=cru=crv=crd=cnt=0;
for (ll i=0; i<n; i++) dis[i]=inf, check[i]=0;
dis[0]=0, update(0), senddis();
}
void receive(bool x)
{
if (cnt<9)
{
if (x) crd^=1<<cnt;
if (++cnt==9)
{
crd+=last;
if (crd>dis[cru])
{
update(cru), sendidx(cru), senddis();
crd=cnt=0;
}
else crv=0;
}
}
else
{
if (x) crv^=1<<cnt-9;
if (++cnt==20)
{
dis[crv]=min(dis[crv], crd);
update(crv), senddis(), cnt=crd=0;
}
}
}
vector <ll> answer()
{
vector <ll> ans(n);
for (ll k=0; k<n; k++) ans[k]=dis[k];
return ans;
}
}
void ReceiveA(bool x) {A::receive(x);}
vector<int> Answer() {return A::answer();}
void InitA(int n, int a, vector<int> U, vector<int> V, vector<int> C)
{
for (ll i=0; i<a; i++)
{
A::A[U[i]].pb({V[i], C[i]});
A::A[V[i]].pb({U[i], C[i]});
}
A::init(n);
}
#include "Baijan.h"
#include<bits/stdc++.h>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;
namespace B
{
const ll maxn=2005, inf=1<<20;
vector <pll> A[maxn];
ll n, last, cru, crd, crv, cnt, dis[maxn], check[maxn];
void update(ll u)
{
check[u]=1, last=dis[u];
for (auto [v, w]:A[u])
dis[v]=min(dis[v], dis[u]+w);
}
void senddis()
{
ll big=-1;
for (ll i=0; i<n; i++)
if (!check[i] && (big==-1 || dis[i]<dis[big]))
big=i;
if (big==-1) return; cru=big;
ll d=min(511, dis[big]-last);
for (ll i=0; i<9; i++) SendB(d>>i&1);
// cout << "A sent distance: " << d << "\n";
}
void sendidx(ll idx) {
// cout << "A sent index: " << idx << "\n";
for (ll i=0; i<11; i++) SendB(idx>>i&1);}
void init(ll N)
{
n=N, last=cru=crv=crd=cnt=0;
for (ll i=0; i<n; i++) dis[i]=inf, check[i]=0;
dis[0]=0, update(0), senddis();
}
void receive(bool x)
{
if (cnt<9)
{
if (x) crd^=1<<cnt;
if (++cnt==9)
{
crd+=last;
if (crd>=dis[cru])
{
update(cru), sendidx(cru), senddis();
crd=cnt=0;
}
else crv=0;
}
}
else
{
if (x) crv^=1<<cnt-9;
if (++cnt==20)
{
dis[crv]=min(dis[crv], crd);
update(crv), senddis(), cnt=crd=0;
}
}
}
}
void ReceiveB(bool x) {B::receive(x);}
void InitB(int n, int b, vector<int> U, vector<int> V, vector<int> C)
{
for (ll i=0; i<b; i++)
{
B::A[U[i]].pb({V[i], C[i]});
B::A[V[i]].pb({U[i], C[i]});
}
B::init(n);
}
Compilation message (stderr)
Azer.cpp: In function 'void A::senddis()':
Azer.cpp:33:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
33 | if (big==-1) return; cru=big;
| ^~
Azer.cpp:33:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
33 | if (big==-1) return; cru=big;
| ^~~
Azer.cpp: In function 'void A::receive(bool)':
Azer.cpp:67:31: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
67 | if (x) crv^=1<<cnt-9;
| ~~~^~
Baijan.cpp: In function 'void B::senddis()':
Baijan.cpp:33:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
33 | if (big==-1) return; cru=big;
| ^~
Baijan.cpp:33:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
33 | if (big==-1) return; cru=big;
| ^~~
Baijan.cpp: In function 'void B::receive(bool)':
Baijan.cpp:67:31: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
67 | if (x) crv^=1<<cnt-9;
| ~~~^~
# | 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... |