#include "Azer.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
typedef long long ll;
const int N = 2000;
const int INF = 1'000'100;
const int M = 20;
int n, m, mark[N + 10], ans[N + 10];
vector<pair<int, int>> adj[N + 10];
set<pair<int, int>> s;
int dis[N + 10];
int bl;
vector<int> detail;
void readInput(int N, int A, vector<int> U, vector<int> V, vector<int> C) {
n = N;
m = A;
for (int i = 0; i < m; i++) {
int u = U[i], v = V[i], c = C[i];
adj[u].push_back({v, c});
adj[v].push_back({u, c});
}
}
void checkDis(int u) {
for (auto [v, w]: adj[u])
if (dis[u] + w < dis[v]) {
s.erase({dis[v], v});
dis[v] = dis[u] + w;
s.insert({dis[v], v});
}
}
void init() {
for (int i = 1; i < n; i++) {
mark[i] = 0;
dis[i] = INF;
s.insert({dis[i], i});
}
dis[0] = 0;
mark[0] = true;
checkDis(0);
}
void outputInt(int x, int M) {
for (int j = M - 1; j >= 0; j--) {
int bit = ((x & (1 << j))? 1: 0);
SendA(bit);
}
}
void outputDis(int x) {
outputInt(x, M);
}
void outputVer(int x) {
outputInt(x, 11);
}
void addVer(int u) {
mark[u] = true;
s.erase({dis[u], u});
ans[u] = dis[u];
checkDis(u);
}
void step() {
bool is = false;
for (int i = 0; i < n; i++)
if (mark[i] == false)
is = true;
if (!is)
return;
bl = true;
outputDis(s.begin() -> first);
}
void newGood(int u, int dist) {
s.erase({dis[u], u});
dis[u] = dist;
addVer(u);
}
void checkDetail() {
int dist = 0, u = 0;
for (int i = 0; i < 20; i++)
dist = dist * 2 + detail[i];
for (int i = 20; i < 31; i++)
u = u * 2 + detail[i];
detail.clear();
newGood(u, dist);
}
}
void InitA(int N, int A, vector<int> U, vector<int> V, vector<int> C) {
readInput(N, A, U, V, C);
init();
step();
}
void ReceiveA(bool x) {
if (bl) {
bl = false;
if (x == 0) {
outputVer(s.begin() -> second);
addVer(s.begin() -> second);
step();
}
}
else {
detail.push_back(x);
if (detail.size() == 31) {
checkDetail();
step();
}
}
}
vector<int> Answer() {
vector<int> res;
for (int i = 0; i < n; i++)
res.push_back(ans[i]);
return res;
}
#include "Baijan.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
typedef long long ll;
const int N = 2000;
const int INF = 1'000'100;
const int M = 20;
int n, m, mark[N + 10], ans[N + 10];
vector<pair<int, int>> adj[N + 10];
set<pair<int, int>> s;
int dis[N + 10];
int readDis, lastDist;
vector<int> detail, vecDis;
void readInput(int N, int A, vector<int> U, vector<int> V, vector<int> C) {
n = N;
m = A;
for (int i = 0; i < m; i++) {
int u = U[i], v = V[i], c = C[i];
adj[u].push_back({v, c});
adj[v].push_back({u, c});
}
}
void checkDis(int u) {
for (auto [v, w]: adj[u])
if (dis[u] + w < dis[v]) {
s.erase({dis[v], v});
dis[v] = dis[u] + w;
s.insert({dis[v], v});
}
}
void init() {
for (int i = 1; i < n; i++) {
dis[i] = INF;
s.insert({dis[i], i});
mark[i] = 0;
}
dis[0] = 0;
mark[0] = true;
checkDis(0);
}
void outputInt(int x, int M) {
for (int j = M - 1; j >= 0; j--) {
int bit = ((x & (1 << j))? 1: 0);
SendB(bit);
}
}
void outputDis(int x) {
outputInt(x, M);
}
void outputVer(int x) {
outputInt(x, 11);
}
void addVer(int u) {
mark[u] = true;
s.erase({dis[u], u});
ans[u] = dis[u];
checkDis(u);
}
void newGood(int u, int dist) {
s.erase({dis[u], u});
dis[u] = dist;
addVer(u);
}
int calcDis() {
int res = 0;
for (int i = 0; i < 20; i++)
res = res * 2 + vecDis[i];
vecDis.clear();
return res;
}
int calcVer() {
int res = 0;
for (int i = 0; i < 11; i++)
res = res * 2 + detail[i];
detail.clear();
return res;
}
}
void InitB(int N, int A, vector<int> U, vector<int> V, vector<int> C) {
readInput(N, A, U, V, C);
init();
readDis = true;
}
void ReceiveB(bool x) {
if (readDis) {
vecDis.push_back(x);
if (vecDis.size() == 20) {
readDis = false;
int dist = calcDis();
if (s.begin() -> first < dist) {
SendB(1);
outputDis(s.begin() -> first);
outputVer(s.begin() -> second);
addVer(s.begin() -> second);
readDis = true;
}
else {
lastDist = dist;
SendB(0);
}
}
}
else {
detail.push_back(x);
if (detail.size() == 11) {
readDis = true;
int u = calcVer();
newGood(u, lastDist);
}
}
}
# | 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... |