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 fi first
#define se second
using namespace std;
const int mxn = 2001;
const int mxval = 9;
const int mxloc = 11;
const int inf = 1e6;
namespace {
int n;
vector<pair<int, int>> adj[mxn];
bool visited[mxn];
vector<int> dist;
int mxdist = 0;
void send_val(int x, int bits) {
vector<bool> send;
for(int i = 0; i < bits; i++) {
send.push_back(x % 2 == 1);
x /= 2;
}
reverse(send.begin(), send.end());
for(bool x : send) SendA(x);
}
int val = 0, tim = 0;
void read_val(int t) {
val = 0;
tim = t;
}
void place(int u, int d) {
visited[u] = true; dist[u] = d;
for(auto e : adj[u]) dist[e.fi] = min(dist[e.fi], dist[u]+e.se);
mxdist = max(mxdist, dist[u]);
}
int gotd = 0;
bool reading_location = false;
pair<int, int> my_mn;
pair<int, int> get_min_dist_loc() {
pair<int, int> res = {(1<<mxval)-1, (1<<mxloc)-1};
for(int i = 0; i < n; i++) if(!visited[i] && dist[i] < inf) {
if(dist[i]-mxdist < res.fi) {
res = {dist[i]-mxdist, i};
}
}
return res;
}
} // namespace
void InitA(int N, int A, vector<int> U, vector<int> V, vector<int> C) {
n = N;
for(int i = 0; i < A; i++) {
adj[U[i]].push_back({V[i], C[i]});
adj[V[i]].push_back({U[i], C[i]});
}
dist = vector<int>(n, inf);
place(0, 0);
if(n == 1) return;
my_mn = get_min_dist_loc();
send_val(my_mn.fi, mxval);
read_val(mxval);
}
void ReceiveA(bool x) {
if(tim > 0) {
val = 2*val+x;
tim--;
}
if(tim > 0) return;
if(!reading_location) {
if(my_mn.fi <= val) {
place(my_mn.se, mxdist+my_mn.fi);
send_val(my_mn.se, mxloc);
if(count(visited, visited+n, true) >= n) return;
my_mn = get_min_dist_loc();
send_val(my_mn.fi, mxval);
read_val(mxval);
}
else {
reading_location = true;
gotd = val;
read_val(mxloc);
}
}
else {
reading_location = false;
place(val, mxdist+gotd);
if(count(visited, visited+n, true) >= n) return;
my_mn = get_min_dist_loc();
send_val(my_mn.fi, mxval);
read_val(mxval);
}
}
vector<int> Answer() {
return dist;
}
#include "Baijan.h"
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int mxn = 2001;
const int mxval = 9;
const int mxloc = 11;
const int inf = 1e6;
namespace {
int n;
vector<pair<int, int>> adj[mxn];
bool visited[mxn];
vector<int> dist;
int mxdist = 0;
void send_val(int x, int bits) {
vector<bool> send;
for(int i = 0; i < bits; i++) {
send.push_back(x % 2 == 1);
x /= 2;
}
reverse(send.begin(), send.end());
for(bool x : send) SendB(x);
}
int val = 0, tim = 0;
void read_val(int t) {
val = 0;
tim = t;
}
void place(int u, int d) {
visited[u] = true; dist[u] = d;
for(auto e : adj[u]) dist[e.fi] = min(dist[e.fi], dist[u]+e.se);
mxdist = max(mxdist, dist[u]);
}
int gotd = 0;
bool reading_location = false;
pair<int, int> my_mn;
pair<int, int> get_min_dist_loc() {
pair<int, int> res = {(1<<mxval)-1, (1<<mxloc)-1};
for(int i = 0; i < n; i++) if(!visited[i] && dist[i] < inf) {
if(dist[i]-mxdist < res.fi) {
res = {dist[i]-mxdist, i};
}
}
return res;
}
} // namespace
void InitB(int N, int A, vector<int> U, vector<int> V, vector<int> C) {
n = N;
for(int i = 0; i < A; i++) {
adj[U[i]].push_back({V[i], C[i]});
adj[V[i]].push_back({U[i], C[i]});
}
dist = vector<int>(n, inf);
place(0, 0);
if(n == 1) return;
my_mn = get_min_dist_loc();
send_val(my_mn.fi, mxval);
read_val(mxval);
}
void ReceiveB(bool x) {
if(tim > 0) {
val = 2*val+x;
tim--;
}
if(tim > 0) return;
if(!reading_location) {
if(my_mn.fi < val) {
place(my_mn.se, mxdist+my_mn.fi);
send_val(my_mn.se, mxloc);
if(count(visited, visited+n, true) >= n) return;
my_mn = get_min_dist_loc();
send_val(my_mn.fi, mxval);
read_val(mxval);
}
else {
reading_location = true;
gotd = val;
read_val(mxloc);
}
}
else {
reading_location = false;
place(val, mxdist+gotd);
if(count(visited, visited+n, true) >= n) return;
my_mn = get_min_dist_loc();
send_val(my_mn.fi, mxval);
read_val(mxval);
}
}
# | 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... |