# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259342 | keko37 | Two Transportations (JOI19_transportations) | C++14 | 0 ms | 0 KiB |
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<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;
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) {
role = ans;
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 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;
}*/