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 X first
#define Y second
using namespace std;
typedef pair<int, int> ii;
#define MAXN 2020
#define pb push_back
#define INF 1001001001
namespace {
int N;
//int variable_example[500000];
int cnt;
vector<ii> g[MAXN];
int dist[MAXN];
set<ii> q;
int getA, getB, getCnt = 0;
int biobr = 0;
} // namespace
void obradiA()
{
ii cu = *q.begin();
q.erase(q.begin());
biobr++;
for (ii i: g[cu.Y]) {
if (dist[i.X] > dist[cu.Y] + i.Y) {
if (q.count({dist[i.X], i.X})) q.erase({dist[i.X], i.X});
dist[i.X] = dist[cu.Y] + i.Y;
q.insert({dist[i.X], i.X});
}
}
if (q.empty()) {
if (biobr == N) return;
for (int i = 0; i < 20; i++) SendA(0);
for (int i = 0; i < 11; i++) SendA(0);
return;
}
ii nx = *q.begin();
for (int i = 0; i < 20; i++) SendA(nx.X & (1 << i));
for (int i = 0; i < 11; i++) SendA(nx.Y & (1 << i));
}
void InitA(int N, int A, std::vector<int> U, std::vector<int> V,
std::vector<int> C) {
::N = N;
if (N == 1) return;
for (int i = 0; i < A; ++i) {
//variable_example[i] = U[i] + V[i] - C[i];
g[U[i]].pb({V[i], C[i]});
g[V[i]].pb({U[i], C[i]});
}
for (int i = 0; i < N; i++) {
dist[i] = INF;
}
dist[0] = 0;
q.insert({0, 0});
obradiA();
}
void ReceiveA(bool x) {
if (getCnt == 0) {
getA = getB = 0;
}
getCnt++;
if (getCnt <= 20) {
if (x)
getA |= (1 << (getCnt - 1));
}
else if (x)
getB |= (1 << (getCnt - 1 - 20));
if (getCnt == 20 + 11) { //cout << getA <<' ' << getB<<endl;
if (dist[getB] > getA) {
if (q.count({dist[getB], getB})) q.erase({dist[getB], getB});
dist[getB] = getA;
q.insert({dist[getB], getB});
}
getCnt = 0;
obradiA();
}
/*++cnt;
if (cnt < 58000) {
SendA(x);
++cnt;
}*/
}
std::vector<int> Answer() {
if (N == 1) return vector<int>(1, 0);
std::vector<int> ans(N);
for (int k = 0; k < N; ++k) {
ans[k] = dist[k];
//ans[k] = variable_example[k];
}
return ans;
}
#include "Baijan.h"
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef pair<int, int> ii;
#define MAXN 2020
#define pb push_back
#define INF 1001001001
namespace {
int N;
int cnt;
vector<ii> g[MAXN];
int dist[MAXN];
set<ii> q;
int getA, getB, getCnt = 0;
int biobr = 0;
bool FunctionExample(bool P) {
return !P;
}
} // namespace
void obradiB()
{
ii cu = *q.begin();
q.erase(q.begin());
biobr++;
for (ii i: g[cu.Y]) {
if (dist[i.X] > dist[cu.Y] + i.Y) {
if (q.count({dist[i.X], i.X})) q.erase({dist[i.X], i.X});
dist[i.X] = dist[cu.Y] + i.Y;
q.insert({dist[i.X], i.X});
}
}
if (q.empty()) {
if (biobr == N) return;
for (int i = 0; i < 20; i++) SendB(0);
for (int i = 0; i < 11; i++) SendB(0);
return;
}
//if (cu.Y == 0) return;
ii nx = *q.begin();
for (int i = 0; i < 20; i++) SendB(nx.X & (1 << i));
for (int i = 0; i < 11; i++) SendB(nx.Y & (1 << i));
}
void InitB(int N, int B, std::vector<int> S, std::vector<int> T,
std::vector<int> D) {
::N = N;
if (N == 1) return;
for (int i = 0; i < B; ++i) {
//variable_example[i] = U[i] + V[i] - C[i];
g[S[i]].pb({T[i], D[i]});
g[T[i]].pb({S[i], D[i]});
}
for (int i = 0; i < N; i++) {
dist[i] = INF;
}
dist[0] = 0;
q.insert({0, 0});
obradiB();
}
void ReceiveB(bool y) {
if (getCnt == 0) {
getA = getB = 0;
}
getCnt++;
if (getCnt <= 20) {
if (y)
getA |= (1 << (getCnt - 1));
}
else if (y)
getB |= (1 << (getCnt - 1 - 20));
if (getCnt == 20 + 11) {
if (dist[getB] > getA) {
if (q.count({dist[getB], getB})) q.erase({dist[getB], getB});
dist[getB] = getA;
q.insert({dist[getB], getB});
}
getCnt = 0;
obradiB();
}
}
Compilation message (stderr)
Azer.cpp:15:5: warning: '{anonymous}::cnt' defined but not used [-Wunused-variable]
int cnt;
^~~
Baijan.cpp:21:6: warning: 'bool {anonymous}::FunctionExample(bool)' defined but not used [-Wunused-function]
bool FunctionExample(bool P) {
^~~~~~~~~~~~~~~
Baijan.cpp:14:5: warning: '{anonymous}::cnt' defined but not used [-Wunused-variable]
int cnt;
^~~
# | 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... |