이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include<Azer.h>
using namespace std;
vector<int> answer, akliczby;
int akwaga = 1, akbit = -1, ak, state, rec, dist, ileod, n, previ;
vector<bool>tym;
bool odwiedzone[2000];
pair<int, int>pqtop;
vector<pair<int, int>> sasiedzi[2000];
priority_queue<pair<int, int>>pq;
void InitA(int N, int A, vector<int>U, vector<int>V, vector<int>C) {
odwiedzone[0] = 1;
n = N;
for (int i = 0; i < N; i++) {
answer.push_back(9999999);
}
answer[0] = 0;
for (int i = 0; i < A; i++) {
sasiedzi[U[i]].push_back({ C[i],V[i] });
sasiedzi[V[i]].push_back({ C[i],U[i] });
}
for (int i = 0; i < N; i++) {
pq.push({ 510,i });
}
for (int i = 0; i < (int)sasiedzi[0].size(); i++) {
pq.push(sasiedzi[0][i]);
}
if (pq.empty())
return;
pqtop = pq.top();
ak = pqtop.first;
for (int i = 0; i < 9; i++) {
SendA(ak % 2);
ak /= 2;
}
}
void ReceiveA(bool x) {
if (ileod == n)
return;
if (state == 0) {
tym.push_back(x);
akbit++;
if (akbit == 9) {
akbit = 0;
rec = 0;
for (int i = 8; i >= 0; i--) {
rec *= 2;
rec += tym[i];
previ += rec;
}
/*!!!!!!!!*/if (rec < pqtop.first) {
state = 1;
dist = rec;
}
else {
previ += pqtop.first;
pq.pop();
ileod++;
if (ileod == n)
return;
odwiedzone[pqtop.second] = 1;
answer[pqtop.second] = pqtop.first;
for (int i = 0; i < (int)sasiedzi[pqtop.second].size(); i++) {
pq.push({ sasiedzi[pqtop.second][i].first + pqtop.first,sasiedzi[pqtop.second][i].second });
}
ak = pqtop.second;
for (int i = 0; i < 11; i++) {
SendA(ak % 2);
ak /= 2;
}
state = 2;
}
}
}
else if (state == 1) {
tym.push_back(x);
akbit++;
if (akbit == 11) {
akbit = 0;
rec = 0;
for (int i = 10; i >= 0; i--) {
rec *= 2;
rec += tym[i];
}
ileod++;
if (ileod == n)
return;
odwiedzone[rec] = 1;
answer[rec] = dist;
for (int i = 0; i < (int)sasiedzi[rec].size(); i++) {
pq.push({ sasiedzi[rec][i].first + dist,sasiedzi[rec][i].second });
}
}
pqtop = pq.top();
while (odwiedzone[pqtop.second]) {
pq.pop();
pqtop = pq.top();
}
ak = pqtop.first - previ;
state = 0;
for (int i = 0; i < 9; i++) {
SendA(ak % 2);
ak /= 2;
}
}
else if (state == 2) {
tym.push_back(x);
akbit++;
if (akbit == 9) {
akbit = 0;
rec = 0;
for (int i = 8; i >= 0; i--) {
rec *= 2;
rec += tym[i];
}
pqtop = pq.top();
while (odwiedzone[pqtop.second]) {
pq.pop();
pqtop = pq.top();
}
ak = pqtop.first;
for (int i = 0; i < 9; i++) {
SendA(ak % 2);
ak /= 2;
}
/*!!!!!!!!*/if (rec < pqtop.first) {
state = 1;
dist = rec;
previ += rec;
}
else {
previ += pqtop.first;
pq.pop();
ileod++;
if (ileod == n)
return;
odwiedzone[pqtop.second] = 1;
answer[pqtop.second] = pqtop.first;
for (int i = 0; i < (int)sasiedzi[pqtop.second].size(); i++) {
pq.push({ sasiedzi[pqtop.second][i].first + pqtop.first,sasiedzi[pqtop.second][i].second });
}
ak = pqtop.second - previ;
for (int i = 0; i < 11; i++) {
SendA(ak % 2);
ak /= 2;
}
state = 2;
}
}
}
}
vector<int> Answer() {
return answer;
}
#include<bits/stdc++.h>
#include<Baijan.h>
using namespace std;
vector<int>answer;
int odwiedzone[2000], ak, n, state, rec, dist, akbit, ileod = 1, previ;
vector<bool>tym;
vector<pair<int, int>> sasiedzi[2000];
priority_queue<pair<int, int>>pq;
pair<int, int>pqtop;
void InitB(int N, int B, vector<int>U, vector<int>V, vector<int>C) {
set<pair<int, pair<int, int>>>krawedzie;
int ak;
for (int i = 0; i < B; i++) {
krawedzie.insert({ C[i],{U[i],V[i]} });
}
odwiedzone[0] = 1;
n = N;
for (int i = 0; i < N; i++) {
answer.push_back(9999999);
}
answer[0] = 0;
for (int i = 0; i < B; i++) {
sasiedzi[U[i]].push_back({ C[i],V[i] });
sasiedzi[V[i]].push_back({ C[i],U[i] });
}
for (int i = 0; i < N; i++) {
pq.push({ 510,i });
}
for (int i = 0; i < (int)sasiedzi[0].size(); i++) {
pq.push(sasiedzi[0][i]);
}
if (pq.empty())
return;
pqtop = pq.top();
ak = pqtop.first;
for (int i = 0; i < 9; i++) {
SendB(ak % 2);
ak /= 2;
}
}
void ReceiveB(bool y) {
cout<<ileod<<" ";
if (ileod == n)
return;
if (state == 0) {
tym.push_back(y);
akbit++;
if (akbit == 9) {
akbit = 0;
rec = 0;
for (int i = 8; i >= 0; i--) {
rec *= 2;
rec += tym[i];
}
/*!!!!!!!!*/if (rec <= pqtop.first) {
state = 1;
dist = rec;
previ += rec;
}
else {
pq.pop();
previ += pqtop.first;
ileod++;
if (ileod == n)
return;
odwiedzone[pqtop.second] = 1;
answer[pqtop.second] = pqtop.first;
for (int i = 0; i < (int)sasiedzi[pqtop.second].size(); i++) {
pq.push({ sasiedzi[pqtop.second][i].first + pqtop.first,sasiedzi[pqtop.second][i].second });
}
ak = pqtop.second;
for (int i = 0; i < 11; i++) {
SendB(ak % 2);
ak /= 2;
}
state = 2;
}
}
}
else if (state == 1) {
tym.push_back(y);
akbit++;
if (akbit == 11) {
akbit = 0;
rec = 0;
for (int i = 10; i >= 0; i--) {
rec *= 2;
rec += tym[i];
}
ileod++;
if (ileod == n)
return;
odwiedzone[rec] = 1;
answer[rec] = dist;
for (int i = 0; i < (int)sasiedzi[rec].size(); i++) {
pq.push({ sasiedzi[rec][i].first + dist,sasiedzi[rec][i].second });
}
}
while (odwiedzone[pqtop.second]) {
pq.pop();
pqtop = pq.top();
}
pqtop = pq.top();
ak = pqtop.first - previ;
state = 0;
for (int i = 0; i < 9; i++) {
SendB(ak % 2);
ak /= 2;
}
}
else if (state == 2) {
tym.push_back(y);
akbit++;
if (akbit == 9) {
akbit = 0;
rec = 0;
for (int i = 8; i >= 0; i--) {
rec *= 2;
rec += tym[i];
}
while (odwiedzone[pqtop.second]) {
pq.pop();
pqtop = pq.top();
}
pqtop = pq.top();
ak = pqtop.first - previ;
for (int i = 0; i < 9; i++) {
SendB(ak % 2);
ak /= 2;
}
/*!!!!!!!!*/if (rec <= pqtop.first) {
state = 1;
dist = rec;
previ += rec;
}
else {
pq.pop();
ileod++;
if (ileod == n)
return;
previ += pqtop.first;
odwiedzone[pqtop.second] = 1;
answer[pqtop.second] = pqtop.first;
for (int i = 0; i < (int)sasiedzi[pqtop.second].size(); i++) {
pq.push({ sasiedzi[pqtop.second][i].first + pqtop.first,sasiedzi[pqtop.second][i].second });
}
ak = pqtop.second;
for (int i = 0; i < 11; i++) {
SendB(ak % 2);
ak /= 2;
}
state = 2;
}
}
}
}
# | 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... |