이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "Azer.h"
using namespace std;
typedef pair <int, int> pi;
const int MAXN = 2005;
int n, m, mx, ans, ex, tip, mn, ind, ost, role;
vector <pi> v[MAXN];
int bio[MAXN], dist[MAXN];
//void SendA (bool x) {}
void SendNum (int val, int br) {
for (int i = br - 1; i >= 0; i--) {
SendA((bool) (val & (1 << i)));
}
}
void update (int x, int d) {
bio[x] = 1; dist[x] = d;
mx = max(mx, dist[x]);
for (auto par : v[x]) {
int sus = par.first, w = par.second;
if (bio[sus] == 0 && dist[x] + w < dist[sus]) dist[sus] = dist[x] + w;
}
}
void solve () {
if (ost == 0) return;
if (tip == 0) {
role = rand() % 2;
SendNum(role, 1);
tip = 1; solve();
} else if (role == 0) {
if (tip == 1) {
mn = 501, ind = -1;
for (int j = 1; j <= n; j++) {
if (bio[j] == 0 && dist[j] - mx < mn) {
mn = dist[j] - mx;
ind = j;
}
}
SendNum(mn, 9);
ans = 0; ex = 1;
} else if (tip == 2) {
if (ans == 0) {
SendNum(ind, 11);
tip = 5;
solve();
} else {
ans = 0; ex = 9;
}
} else if (tip == 3) {
mn = ans;
ans = 0; ex = 11;
} else if (tip == 4) {
ind = ans;
tip = 5;
solve();
} else if (tip == 5) {
update(ind, mx + mn);
tip = 0;
ost--;
solve();
}
} else {
if (tip == 1) {
mn = 501, ind = -1;
for (int j = 1; j <= n; j++) {
if (bio[j] == 0 && dist[j] - mx < mn) {
mn = dist[j] - mx;
ind = j;
}
}
ans = 0; ex = 9;
} else if (tip == 2) {
if (mn < ans) {
SendNum(1, 1);
SendNum(mn, 9);
SendNum(ind, 11);
tip = 4;
solve();
} else {
SendNum(0, 1);
mn = ans;
ans = 0; ex = 11;
}
} else if (tip == 3) {
ind = ans;
tip = 4;
solve();
} else if (tip == 4) {
update(ind, mx + mn);
tip = 0;
ost--;
solve();
}
}
}
void ReceiveA (bool x) {
ans *= 2;
if (x) ans++;
ex--;
if (ex == 0) {
tip++;
solve();
}
}
std::vector<int> Answer () {
vector <int> res(n);
for (int i = 0; i < n; i++) res[i] = dist[i];
return res;
}
void InitA (int N, int A, std::vector <int> U, std::vector <int> V, std::vector <int> C) {
n = N; m = A;
for (int i = 0; i < m; i++) {
v[U[i]].push_back({V[i], C[i]});
v[V[i]].push_back({U[i], C[i]});
}
for (int i = 1; i <= n; i++) dist[i] = 1e9;
update(0, 0);
ost = n-1;
solve();
}
/*int main () {
return 0;
}*/
#include<bits/stdc++.h>
#include "Baijan.h"
using namespace std;
typedef pair <int, int> pi;
const int MAXN = 2005;
int n, m, mx, ans, ex, tip, mn, ind, ost, role;
vector <pi> v[MAXN];
int bio[MAXN], dist[MAXN];
//void SendB (bool x) {}
void SendNum (int val, int br) {
for (int i = br - 1; i >= 0; i--) {
SendB((bool) (val & (1 << i)));
}
}
void update (int x, int d) {
bio[x] = 1; dist[x] = d;
mx = max(mx, dist[x]);
for (auto par : v[x]) {
int sus = par.first, w = par.second;
if (bio[sus] == 0 && dist[x] + w < dist[sus]) dist[sus] = dist[x] + w;
}
}
void solve () {
if (ost == 0) return;
if (tip == 0) {
ans = 0; ex = 1;
} else if (tip == 1) {
role = !ans;
tip++; solve();
} else if (role == 0) {
if (tip == 2) {
mn = 501, ind = -1;
for (int j = 1; j <= n; j++) {
if (bio[j] == 0 && dist[j] - mx < mn) {
mn = dist[j] - mx;
ind = j;
}
}
SendNum(mn, 9);
ans = 0; ex = 1;
} else if (tip == 3) {
if (ans == 0) {
SendNum(ind, 11);
tip = 6;
solve();
} else {
ans = 0; ex = 9;
}
} else if (tip == 4) {
mn = ans;
ans = 0; ex = 11;
} else if (tip == 5) {
ind = ans;
tip = 6;
solve();
} else if (tip == 6) {
update(ind, mx + mn);
tip = 0;
ost--;
solve();
}
} else {
if (tip == 2) {
mn = 501, ind = -1;
for (int j = 1; j <= n; j++) {
if (bio[j] == 0 && dist[j] - mx < mn) {
mn = dist[j] - mx;
ind = j;
}
}
ans = 0; ex = 9;
} else if (tip == 3) {
if (mn < ans) {
SendNum(1, 1);
SendNum(mn, 9);
SendNum(ind, 11);
tip = 5;
solve();
} else {
SendNum(0, 1);
mn = ans;
ans = 0; ex = 11;
}
} else if (tip == 4) {
ind = ans;
tip = 5;
solve();
} else if (tip == 5) {
update(ind, mx + mn);
tip = 0;
ost--;
solve();
}
}
}
void ReceiveB (bool x) {
ans *= 2;
if (x) ans++;
ex--;
if (ex == 0) {
tip++;
solve();
}
}
void InitB (int N, int B, std::vector <int> U, std::vector <int> V, std::vector <int> C) {
n = N; m = B;
for (int i = 0; i < m; i++) {
v[U[i]].push_back({V[i], C[i]});
v[V[i]].push_back({U[i], C[i]});
}
for (int i = 1; i <= n; i++) dist[i] = 1e9;
update(0, 0);
ost = n-1;
solve();
}
/*int main () {
return 0;
}*/
# | 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... |