# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1097860 | thangdz2k7 | Two Transportations (JOI19_transportations) | C++17 | 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;
using vi = vector <int>;
using ii = pair <int, int>;
const int N = 2000;
const int inf = 1e9;
const int L = 9;
const int MaxE = (1 << L) - 1;
int n, m, D;
vector <ii> adj[N];
vi dist, used;
void upd(int x){
used[x] = 1;
for (auto [w, v] : adj[x]) dist[v] = min(dist[v], dist[x] + w);
}
int Node, cnt, X, op;
void Send(){
int Y = inf; bool ok = false;
for (int u = 0; u < n; ++ u) if (!used[u]){
ok = true;
if (dist[u] < Y) Y = dist[u], Node = u;
}
if (!ok) return; op = 1;
Y -= D; Y = min(Y, MaxE);
for (int i = L - 1; i >= 0; -- i) SendA(Y >> i & 1);
}
void InitA(int NN, int A, vi U, vi V, vi C){
n = NN, m = A;
for (int i = 0; i < A; ++ i) {
adj[U[i]].pb({C[i], V[i]});
adj[V[i]].pb({C[i], U[i]});
}
dist.resize(n, inf); used.resize(n, 0);
dist[0] = 0; D = 0; upd(0); Send();
}
void ReceiveA(bool x){
X = X * 2 + x; ++ cnt;
if (op == 1){
if (cnt == L){
if (Y <= X){
for (int i = 10; i >= 0; -- i) SendA(Node >> i & 1);
D += Y; upd(Node); Send();
cnt = 0, X = 0;
}
else {
D += X; w = 2; cnt = 0; X = 0;
}
}
} else if (op == 2){
if (cnt == 11){
dist[X] = D; upd(X); Send(); cnt = 0; X = 0;
}
}
}
vi Answer(){ return dist; }
#include <bits/stdc++.h>
#include "Baijan.h"
using namespace std;
using vi = vector <int>;
using ii = pair <int, int>;
const int N = 2000;
const int inf = 1e9;
const int L = 9;
const int MaxE = (1 << L) - 1;
int n, m, D;
vector <ii> adj[N];
vi dist, used;
void upd(int x){
used[x] = 1;
for (auto [w, v] : adj[x]) dist[v] = min(dist[v], dist[x] + w);
}
int Node, cnt, X, op;
void Send(){
int Y = inf; bool ok = false;
for (int u = 0; u < n; ++ u) if (!used[u]){
ok = true;
if (dist[u] < Y) Y = dist[u], Node = u;
}
if (!ok) return; op = 1;
Y -= D; Y = min(Y, MaxE);
for (int i = L - 1; i >= 0; -- i) SendA(Y >> i & 1);
}
void InitB(int NN, int B, vi U, vi V, vi C){
n = NN, m = B;
for (int i = 0; i < B; ++ i) {
adj[U[i]].pb({C[i], V[i]});
adj[V[i]].pb({C[i], U[i]});
}
dist.resize(n, inf); used.resize(n, 0);
dist[0] = 0; D = 0; upd(0); Send();
}
void ReceiveB(bool y){
X = X * 2 + y; ++ cnt;
if (op == 1){
if (cnt == L){
if (Y < X){
for (int i = 10; i >= 0; -- i) SendB(Node >> i & 1);
D += Y; upd(Node); Send(); cnt = 0, X = 0;
}
else {
D += X; w = 2; cnt = 0; X = 0;
}
}
} else if (op == 2){
if (cnt == 11){
dist[X] = D; upd(X); Send(); cnt = 0; X = 0;
}
}
}