이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
#include "Azer.h"
using namespace std;
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
namespace {
const int NLOG = 11, CLOG = 9;
const int INF = 1000000005;
const int FINF = (1 << CLOG) - 2;
const int MAXN = 200005;
int n, m;
vii adj[MAXN];
queue<bool> qu;
int vis[MAXN];
vi dist;
bool waitDist;
int pd;
int get(int bits) {
int x = 0;
REP (i, 0, bits) {
x += qu.front() << i;
qu.pop();
}
return x;
}
void send(int x, int bits) {
REP (i, 0, bits) {
SendA(x >> i & 1);
}
}
ii dijkstra() {
int u = -1, d = INF + 1;
REP (i, 0, n) {
if (vis[i]) continue;
if (mnto(d, dist[i])) {
u = i;
}
}
return {u, d};
}
void relax(int u) {
for (auto [v, w] : adj[u]) {
mnto(dist[v], dist[u] + w);
}
}
}
void InitA(int N, int A, vi U, vi V, vi C) {
n = N; m = A;
REP (i, 0, m) {
adj[U[i]].pb({V[i], C[i]});
adj[V[i]].pb({U[i], C[i]});
}
dist = vi(n, INF);
dist[0] = 0;
auto [u, d] = dijkstra();
send(d, CLOG);
waitDist = 1;
}
void ReceiveA(bool x) {
qu.push(x);
bool found = 0;
if (waitDist) {
if (qu.size() == CLOG) {
int nd = get(CLOG) + pd;
auto [u, d] = dijkstra();
cerr << "A " << nd << ' ' << d << '\n';
if (d < nd) {
send(u, NLOG);
pd = d;
vis[u] = 1;
found = 1;
relax(u);
} else {
waitDist = 0;
pd = nd;
}
}
} else {
if (qu.size() == NLOG) {
int u = get(NLOG);
cerr << "A u " << u << '\n';
dist[u] = pd;
relax(u);
vis[u] = 1;
waitDist = 1;
found = 1;
}
}
if (found) {
auto [u, d] = dijkstra();
cerr << " A " << u << ' ' << d << '\n';
if (u != -1) {
send(min(d - pd, FINF), CLOG);
}
}
}
vi Answer() {
return dist;
}
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
#include "Baijan.h"
using namespace std;
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
namespace {
const int NLOG = 11, CLOG = 9;
const int INF = 1000000005;
const int FINF = (1 << CLOG) - 2;
const int MAXN = 200005;
int n, m;
vii adj[MAXN];
queue<bool> qu;
int vis[MAXN];
vi dist;
bool waitDist;
int pd;
int get(int bits) {
int x = 0;
REP (i, 0, bits) {
x += qu.front() << i;
qu.pop();
}
return x;
}
void send(int x, int bits) {
REP (i, 0, bits) {
SendB(x >> i & 1);
}
}
ii dijkstra() {
int u = -1, d = INF + 1;
REP (i, 0, n) {
if (vis[i]) continue;
if (mnto(d, dist[i])) {
u = i;
}
}
return {u, d};
}
void relax(int u) {
for (auto [v, w] : adj[u]) {
mnto(dist[v], dist[u] + w);
}
}
}
void InitB(int N, int A, vi U, vi V, vi C) {
n = N; m = A;
REP (i, 0, m) {
adj[U[i]].pb({V[i], C[i]});
adj[V[i]].pb({U[i], C[i]});
}
dist = vi(n, INF);
dist[0] = 0;
auto [u, d] = dijkstra();
send(d, CLOG);
waitDist = 1;
}
void ReceiveB(bool x) {
qu.push(x);
bool found = 0;
if (waitDist) {
if (qu.size() == CLOG) {
int nd = get(CLOG) + pd;
auto [u, d] = dijkstra();
cerr << "B " << nd << ' ' << d << '\n';
if (d <= nd) {
send(u, NLOG);
pd = d;
vis[u] = 1;
found = 1;
relax(u);
} else {
waitDist = 0;
pd = nd;
}
}
} else {
if (qu.size() == NLOG) {
int u = get(NLOG);
cerr << "B u " << u << '\n';
dist[u] = pd;
relax(u);
vis[u] = 1;
waitDist = 1;
found = 1;
}
}
if (found) {
auto [u, d] = dijkstra();
cerr << " B " << u << ' ' << d << '\n';
if (u != -1) {
send(min(d - pd, FINF), CLOG);
}
}
}
# | 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... |