#include "Encoder.h"
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define isz(x) (int)x.size()
using namespace std;
void Encode(int N, int A[], int B[]) {
vector<vector<int>> g(N);
for (int i = 0; i < N - 1; ++i) {
int u = A[i], v = B[i];
g[u].emplace_back(v);
g[v].emplace_back(u);
}
int tdfs = 0;
vector<i64> tin(N), tout(N);
auto dfs = [&](auto self, int u, int p) -> void {
tin[u] = tdfs++;
for (auto v : g[u]) if (v != p) {
self(self, v, u);
}
tout[u] = tdfs;
};
dfs(dfs, 0, -1);
for (int i = 0; i < N; ++i) {
if (tout[i] >= (1 << 17)) {
int nN = (1 << 18) - 1;
Code(i, (nN - tin[i]) << 17 | (nN - tout[i]));
}
else {
Code(i, tin[i] << 17 | tout[i]);
}
}
}
#include "Device.h"
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define isz(x) (int)x.size()
using namespace std;
void InitDevice() {
}
const int lim = (1 << 18) - 1;
int Answer(i64 S, i64 T) {
int Sl = S >> 17, Sr = S & lim;
if (Sl > Sr) Sl = lim - Sl, Sr = lim - Sr;
int Tl = T >> 17, Tr = T & lim;
if (Tl > Tr) Tl = lim - Tl, Tr = lim - Tr;
if (Tl <= Sl and Sr <= Tr) return 0;
if (Sl <= Tl and Tr <= Sr) return 1;
return 2;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |