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;
using ar = array<int,2>;
using vi = vector<int>;
#define pb push_back
namespace {
const int mxN = (int)2e3+10;
int n,dis[mxN];
vector<ar> adj[mxN];
void dijkstra(){
priority_queue<ar,vector<ar>,greater<ar>> pq;
memset(dis,63,sizeof(dis));
pq.push({0,0}); dis[0]=0;
while(!pq.empty()){
auto [D,a] = pq.top(); pq.pop();
if(D!=dis[a]) continue;
for(auto [b,w] : adj[a])
if(dis[b]>dis[a]+w)
dis[b]=dis[a]+w,pq.push({dis[b],b});
}
}
void Send(int x, int sz){
for(int i = 0; i < sz; i++)
SendA((x>>i)&1);
}
}
void InitA(int N, int A, vi U, vi V, vi C) {
n = N; fill(dis,dis+mxN,0);
for (int i = 0; i < A; ++i) {
adj[U[i]].pb({V[i],C[i]});
adj[V[i]].pb({U[i],C[i]});
}
}
int u=0, v=0, c=0, xd=0;
void ReceiveA(bool x) {
if(xd<11) v|=(1<<xd)*x;
else c|=(1<<(xd-11))*x;
xd++;
if(xd==20){
if(v!=(1<<11)-1) adj[u].pb({v,c}),adj[v].pb({u,c});
xd = v = c = 0; u++;
}
}
vi Answer() {
dijkstra();
vi ans(n,0);
for(int k = 1; k < n; ++k)
ans[k] = dis[k];
return ans;
}
#include "Baijan.h"
#include <bits/stdc++.h>
using namespace std;
using ar = array<int,2>;
using vi = vector<int>;
#define pb push_back
namespace {
const int mxN = (int)2e3+10;
int n,dis[mxN],par[mxN],W[mxN];
vector<ar> adj[mxN];
void dijkstra(){
priority_queue<ar,vector<ar>,greater<ar>> pq;
memset(dis,63,sizeof(dis));
pq.push({0,0}); dis[0]=0;
while(!pq.empty()){
auto [D,a] = pq.top(); pq.pop();
if(D!=dis[a]) continue;
for(auto [b,w] : adj[a])
if(dis[b]>dis[a]+w)
dis[b]=dis[a]+w,pq.push({dis[b],b});
}
}
void Send(int x, int sz){
for(int i = 0; i < sz; i++)
SendB((x>>i)&1);
}
void dfs(int s, int p){
for(auto [u,w] : adj[s]){
if(u!=p) par[u]=s,W[u]=w, dfs(u,s);
}
}
}
void InitB(int N, int B, vi U, vi V, vi C) {
n = N; fill(dis,dis+mxN,0);
fill(par,par+mxN,-1);
for (int i = 0; i < B; ++i) {
adj[U[i]].pb({V[i],C[i]});
adj[V[i]].pb({U[i],C[i]});
}
for(int i = 0; i < n; i++)
if(par[i]==-1) dfs(i,-1);
for(int i = 0; i < n; i++){
if(par[i]==-1) Send((1<<11)-1,11),Send(0,9);
else Send(par[i],11),Send(W[i],9);
}
}
void ReceiveB(bool y) {
}
Compilation message (stderr)
Azer.cpp:24:7: warning: 'void {anonymous}::Send(int, int)' defined but not used [-Wunused-function]
24 | void Send(int x, int sz){
| ^~~~
Baijan.cpp:12:7: warning: 'void {anonymous}::dijkstra()' defined but not used [-Wunused-function]
12 | void dijkstra(){
| ^~~~~~~~
# | 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... |