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/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
void encode_bit(int b);
void write(int bits, int x) {
for (int i = 0; i < bits; i++) {
encode_bit((x >> i) & 1);
}
}
void encode(int n, int k, int m, int us[], int vs[]) {
int dist[1024];
vector<int> graph[n];
for (int i = 0; i < m; i++) {
graph[us[i]].push_back(vs[i]);
graph[vs[i]].push_back(us[i]);
}
auto bfs = [&](int src) -> void {
memset(dist, -1, sizeof(dist));
queue<int> q;
auto push = [&](int u, int d) -> void {
if (dist[u] == -1) {
dist[u] = d;
q.push(u);
}
};
push(src, 0);
while (sz(q)) {
int u = q.front();
q.pop();
for (auto& v : graph[u]) {
push(v, dist[u] + 1);
}
}
};
vector<pair<int, int>> ans;
for (int i = 0; i < k; i++) {
bfs(i);
bool vis[n] {};
for (auto [u, v] : ans) {
if (abs(dist[u] - dist[v]) == 1) {
if (dist[u] > dist[v]) {
swap(u, v);
}
vis[v] = true;
}
}
for (int j = 0; j < m; j++) {
int u = us[j], v = vs[j];
if (abs(dist[u] - dist[v]) == 1) {
if (dist[u] > dist[v]) {
swap(u, v);
}
if (!vis[v]) {
ans.emplace_back(u, v);
vis[v] = true;
}
}
}
}
for (auto& [u, v] : ans) {
write(10, u);
write(10, v);
}
write(10, 1023);
}
#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
int decode_bit();
void hops(int h, int c, int d);
int read(int bits) {
int x = 0;
for (int i = 0; i < bits; i++) {
x |= decode_bit() << i;
}
return x;
}
void decode(int n, int k) {
int dist[1024];
vector<int> graph[n];
while (true) {
int u = read(10);
if (u == 1023) {
break;
}
int v = read(10);
graph[u].push_back(v);
graph[v].push_back(u);
}
auto bfs = [&](int src) -> void {
memset(dist, -1, sizeof(dist));
queue<int> q;
auto push = [&](int u, int d) -> void {
if (dist[u] == -1) {
dist[u] = d;
q.push(u);
}
};
push(src, 0);
while (sz(q)) {
int u = q.front();
q.pop();
for (auto& v : graph[u]) {
push(v, dist[u] + 1);
}
}
};
for (int i = 0; i < k; i++) {
bfs(i);
for (int j = 0; j < n; j++) {
hops(i, j, dist[j]);
}
}
}
# | 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... |